Tags priority/order

Hi there,

Is it possible to have tags on the front listing page in order, based on the priority set in the back end? I have set a fixed number of tags, in certain order, and users cannot add any more tags to it.

2023-02-15 (3)

Thank you!

Hi,

Please try this PHP snippet:

add_filter( 
 'hivepress/v1/models/listing/attributes', 
 function($attributes){
  if(isset($attributes['tags'])){
   
   // Please choose one of the order ways and please remove another one
   // First order way. Order by priority from 0
   $attributes['tags']['edit_field']['option_args']['order'] = 'ASC';
   
   // Second order way. Order by priority from the biggest priority number among tags
   $attributes['tags']['edit_field']['option_args']['order'] = 'DESC';
  
   // Please do not remove it
   $attributes['tags']['edit_field']['option_args']['orderby'] = 'meta_value';
   $attributes['tags']['edit_field']['option_args']['meta_key'] = 'hp_sort_order';
  }
  return $attributes;
 },
 1000
);

Please note that it can require advanced customization.
If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY.

1 Like

Hi Andrii, thank you. This works well for the Listing edit page.

Would you be able to adjust the snippet for it to work on Listings page filter area?

Thank you.

Please try this PHP snippet for the listing filter form

add_filter( 
	'hivepress/v1/models/listing/attributes', 
	function($attributes){
		if(isset($attributes['tags'])){
   
   			// Please choose one of the order ways and please remove another one
   			// First order way. Order by priority from 0
   			$attributes['tags']['search_field']['option_args']['order'] = 'ASC';
   
   			// Second order way. Order by priority from the biggest priority number among tags
   			$attributes['tags']['search_field']['option_args']['order'] = 'DESC';
			
			// If you want to show empty tags then please leave this part. By default, empty tags are hidden
			$attributes['tags']['search_field']['option_args']['hide_empty'] = false;
  
   			// Please do not remove it
   			$attributes['tags']['search_field']['option_args']['orderby'] = 'meta_value';
   			$attributes['tags']['search_field']['option_args']['meta_key'] = 'hp_sort_order';
  		}
  		return $attributes;
 	},
 	1000
);
1 Like

Thank you Yevhen, it works perfectly.

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