How to change a WordPress term’s slug before saving

You add the following snippet to your theme’s functions.php file; The “wp_insert_term_data” filter allows you to modify a term’s name, slug or term_group before it is added to the database. This works for terms added via WP All Import and also manually through admin as well. The filter passes all taxonomy terms, not just woocommerce … Read more

How to display custom taxonomy term meta on custom post type

1. If you need to display this informations once. For example in the page header, use get_queried_object(). echo get_term_meta( get_queried_object()->term_id, ‘blue’, true ); echo get_term_meta( get_queried_object()->term_id, ‘red’, true ); echo get_term_meta( get_queried_object()->term_id, ‘green’, true ); 2. If you need to display this informations in the each post, you must create a small loop. $terms = … Read more

Matching slug terms from one array to those in array of WP_Term objects to output term names

Perhaps array_map ? This will give you an array of term names which matched your slugs in $active_filters: $matched_terms = array_map(function($term) use ($active_filters){ if(in_array($term->slug, $active_filters)){ return $term->name; } else{ return false; } }, $tax_terms); //remove the empty array elements which came from terms which didn’t match a slug $matched_terms = array_filter($matched_terms);

How to return newly added terms when using wp_set_object_terms

You can add a filter for a specific function call like so: add_filter( ‘set_object_terms’, ‘checkNewTerm’, 10, 6 ); function checkNewTerm( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) { // Do stuff, ie. compare count of $tt_ids and $old_tt_ids } wp_set_object_terms($id, array($migrate_case), ‘pa_case’); remove_filter( ‘set_object_terms’, ‘checkNewTerm’, 10, 6 );

How can I change the output display of my pagination?

I could see that you are trying to achieve the following output: <div class=”pagination”> <span>Page {current} of {total pages}</span> {links here} </div> And you attempted it like so: ‘before_page_number’ => ‘<div class=”pagination”><span>Page ‘. // wrapped for clarity $paged .’ of ‘ . $term->max_num_pages . ‘</span></div>’ But that will actually add the markup before each and … Read more

Echo term slug op post on archive page

The get_the_terms function returns array of WP_Term objects. So you need to use something like this to echo a single term slug: echo $terms[0]->slug; Also be aware of results of this function. As documentation says it returns: Array of WP_Term objects on success, false if there are no terms or the post does not exist, … Read more