Non-permalink custom taxonomy not found

The problem was ‘exclude_from_search’ => true in the register_post_type options. Given that setting ‘public’ => true defaults to exluding from search by default I assumed that this was the correct setting. However this is in the WordPress codex for register_post_type exclude_from_search: Note: If you want to show the posts’s list that are associated to taxonomy’s … Read more

Sort and paginate custom post taxonomies alphabetically

As I stated in comments, you can either use usort() to sort the returned array of terms, or you can just use wp_get_post_terms() which is already sorted by default by name in ascending order $terms = wp_get_post_terms( get_the_ID(), ‘brand’ ); var_dump( $terms ); EDIT Here is an example with usort() and get_the_terms() $terms = get_the_terms( … Read more

Copy/Move selected taxonomy terms to another taxonomy for posts

This will get all posts with $old_tax, copy the terms from $old_tax to $new_tax, and then set the $new_tax terms for those posts. <?php function convert_tax($old_tax, $new_tax) { $pages = get_posts(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => $old_tax, ‘operator’ => ‘EXISTS’ ) ) )); foreach($pages as $post) { $terms … Read more

Using WP_Query, I want to show posts that are associated with a custom taxonomy term

Your tax query should be an array of arrays. Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy arrays. https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters ‘tax_query’ … Read more

WordPress autocomplete search with taxonomies

Ok I got it! That’s the code for my search-results.php <?php include(‘../../../wp-load.php’); $term=$_GET[“term”]; $json=array(); $terms = get_terms( ‘produits’ ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ foreach ( $terms as $term ) { $json[]=array( ‘value’=> $term->name ); } } echo json_encode($json); ?> Thanks milo for your help ! I needed … Read more

Show post count number assigned to custom taxonomy

Normally usage of get_term() or get_term_by() is pretty much clear cut. See the basic example below: // ID is needed $term_by_id = get_term( 12345, ‘destination’ ); echo $term_by_id->count; // Or if you e.g. want use the name (or slug or id or term_taxonomy_id) $term_by_name = get_term_by( ‘name’, ‘greece’, ‘destination’ ); echo $term_by_name->count; Note: I said … Read more