Remove ‘Date’ as a sort by option

Hi,

I have removed the “Title” as a sorting option in listings but have been unable to remove the “Date” sorting option.

Could someone please help me with this?

Thanks

Please try this PHP snippet but please note that it can require further customization

add_filter(
	'hivepress/v1/forms/listing_sort',
	function( $form ) {
		unset( $form['fields']['_sort']['options'][''] );

		return $form;
	},
  1000
);

Please clarify if you want to replace it with another sorting option? Because it may be not possible to remove the Date one, it basically means “no sorting” and listings are displayed by date or relevance (if there’s a search query), some option has to be the default one.

I have created an attribute to sort the listings but the date option is the first option selected by default. The only way I could think of solving it would be to remove the date option. Unless there is a way around this?

Yes, the code snippet above will remove the default option but the sorting will remain, unfortunately there’s no easy way to select an attribute as the default sorting criteria but we have this feature on the roadmap.

Thanks, we have this on the roadmap and will try to implement this as soon as possible.

Hi @jacqueball98, could you pls share a snippet to remove “Title” as a sorting option? (or a different way you did it?)
Thanks a lot!

Please try this PHP snippet

add_filter(
	'hivepress/v1/forms/listing_sort',
	function( $form ) {
		unset( $form['fields']['_sort']['options']['title'] );

		return $form;
	}
);
1 Like

thanks a lot @yevhen!
is there a similar way to remove reviews/ratings as a sorting option?

I tried to replace ‘title’ from the previous snippet with ‘rating__asc’ or ‘rating__desc’ but it didn’t work…

thx!

If you want to remove the rating sorting option only for listings then please try this PHP snippet

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function($attributes){
		if(isset($attributes['rating'])){
			$attributes['rating']['sortable'] = false;
		}
		
		return $attributes;
	}, 
	1000 
);
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.