This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Change term order of Taxonomy Frontend outpus

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Change term order of Taxonomy Frontend outpus Reply To: Change term order of Taxonomy Frontend outpus

#35753
willfaulds59willfaulds59
Participant

Excellent! Thank you.

Posting to help others in the future

add_filter( 'asp_fontend_get_taxonomy_terms', 'asp_reorder_terms', 1, 3 );
function asp_reorder_terms($terms, $taxonomy, $args) {
	if ( $taxonomy == 'product_tag' ) {//'product_tag' is for WooCommerce

		$custom_order = [ 'slug2' , 'slug3' , 'slug4' , 'slug1' ];//desired order of terms using their slug
		$terms_reordered = [];
		$i = 0;
		foreach($custom_order as $slug => $data){
			foreach($terms as $term){
				if($term->slug == $slug){
					$terms_reordered[$i] = $term;
					unset($term);//unset so mark it reordered
				}
			}
			$i++;
		}
		return array_merge($terms_reordered, $terms);//merge in any terms not reordered
	}

	return $terms;
}
  • This reply was modified 4 years, 6 months ago by willfaulds59willfaulds59.