Default order by modified date for listings?

Hello,

Is it possible to change the default order from “created_date” to “modified_date” in an easy way?. I have successfully done it by editing the render function in “includes\blocks\class-listings.php” but I want to avoid this method.

Is is posible to do it by any other way? For example:

  1. A simple filter in functions.php to change the block. Maybe with an action?
  2. Is it possible to redefine the whole public function “render()” in this functions.php.

I have been testing with these two options with no results.

Thanks and best regards,

Sorry for the delay.

If you’re familiar with customizations, I recommend using the pre_get_posts hook, you can check if it’s the main query there and if the post type is hp_listing, then adjust the query in any way. Another solution is using the hivepress/v1/models/listing/search hook, but in the current version it fires only if the search is performed, not when the common Listings page is being viewed.

Thanks Ihor,

Finally done by this way. It seems to work properly:

add_action(
	'pre_get_posts',
	function($query){
		if ( 'hp_listing' == $query->get( 'post_type' ) ) {
			$query->set( 'orderby', 'modified' );
			$query->set( 'order', 'DESC' );
		}	
	},
	1000
);

Thanks and regards,