How Parent Taxonomy automatically added to the post when using `wp_set_object_terms()`?

You can use get_ancestors() to get parents and grandparents etc. of a term, then use that in wp_set_object_terms(): $term_id = 12; // Get array of term parents. $terms = get_ancestors( $term_id, ‘topic’ ); // Include original term in array. $terms[] = $term_id; // Add parents and original term to post. wp_set_object_terms( $post_id, $terms, ‘topic’, true … Read more

Which Template Page Should I Use?

you could always make a custom wp_query and put it in a template-custom.php. $the_query = new WP_Query( array( ‘post_type’ => ‘faqs’, ‘tax_query’ => array( array ( ‘taxonomy’ => ‘audiences’, ‘field’ => ‘slug’, ‘terms’ => ‘merchants’, ) ), ) ); while ( $the_query->have_posts() ) : $the_query->the_post(); // Show Posts … the_title(); endwhile; /* Restore original Post … Read more

Main query not querying any posts in custom taxonomy template

I think the issue here is that when registering the post type, you’ve set exclude_from_search to true. See this note from the WordPress Coedex: Note: If you want to show the posts’s list that are associated to taxonomy’s terms, you must set exclude_from_search to false (ie : for call site_domaine/?taxonomy_slug=term_slug or site_domaine/taxonomy_slug/term_slug). If you set … Read more

WP_Query for a taxonomy with different taxonomy types

You can create a taxonomy query. Assuming that “curso” is the term slug, it would look like this: $query = new WP_Query( array( ‘post_type’ => ‘obras_en_curso’, ‘posts_per_page’ => 4, ‘tax_query’ => array( array( ‘taxonomy’ => ‘casa_unifamiliar’, ‘field’ => ‘slug’, ‘terms’ => ‘curso’, ), ), ) ); For more information, see: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

WP_Query args to show posts from specific custom taxonomy

Taxonomy query doesn’t work without terms parameter. So you have to first query all the regions term then assign term ids to taxonomy query. Here’s the solution – $terms = get_terms( array( ‘taxonomy’ => ‘regions’, ‘fields’ => ‘id=>slug’, ) ); $args = array( ‘orderby’ => ‘date’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, … Read more

If Custom Taxonomy

get_the_term_list() returns a string of HTML for the list of taxonomy terms on the given post. Without giving values in the optional arguments it would look like this: <a href=”http://example.com/type/roast/” rel=”tag”>Roast</a> <a href=”http://example.com/type/type2/” rel=”tag”>Type 2</a> So $type == ‘roast’ would not be true because the value isn’t anything close to ‘roast’. Even if it returned … Read more

Custom Post type & Taxonomy 404

Please replace the “portfolio_create_taxonomy” funcation to below code function portfolio_create_taxonomy() { register_taxonomy( ‘portfolio-category’, array( ‘portfolio’ ), array( ‘hierarchical’ => true, ‘show_ui’ => true, ‘show_admin_column’ => true, ‘query_var’ => true, ‘label’ => __( ‘Category’ ), ‘rewrite’ => array( ‘slug’ => ‘portfolio-category’ ), ‘hierarchical’ => true, ) ); } add_action( ‘init’, ‘portfolio_create_taxonomy’ );