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

Display specific Taxonomy Term from Custom Post Type

Please use valid format for this Taxonomy Parameters Example: $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘topics’, ‘field’ => ‘slug’, ‘terms’ => ‘dealoftheweek’, ), ), ‘post_type’ => ‘dealmaker_pt’, ‘posts_per_page’ => 50, ‘offset’ => 1 ); $query = new WP_Query( $args );

How to display parents category and child category separately for a specific post?

This should find an immediate parent for you. // get the current category ID $category_id = get_the_category(get_the_ID()); // get the current category object $child = get_category($category_id[0]->term_id); // get it’s parent object $parent = get_category($child->parent); var_dump($parent->name . ‘ – ‘ . $child->name); The same but in a WordPress loop: $args = [ ‘post_type’ => ‘post’ ]; … Read more

Get Post Terms of Current Post (selected taxonomy term) – How to get only the taxonomy value and not “Array ( [0] => taxonomy term )” in the frontend?

Assuming the taxonomy name is “animals” <?php //This will show all the terms in taxonomy whether they have posts or not thus the “hide_empty” $terms = get_terms( array ( ‘taxonomy’ => ‘animals’, ‘hide_empty’ => false, ‘parent’ => 0, ‘orderby’ => ‘description’, ‘order’ => ‘ASC’ )); foreach ($terms as $term) { // The $term is an … 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

Custom Taxonomy Category link

You have to add a taxonomy category for your new custom post type such as function mvli_customtype_category() { register_taxonomy( ‘customtype-category’, ‘customtype’, array( ‘label’ => __( ‘Category’ ), ‘rewrite’ => array( ‘slug’ => ‘customtype-category’ ), ‘hierarchical’ => true, ) ); } add_action( ‘init’, ‘mvli_customtype_category’ ); And then you can easily open the link like this website.com/customtype-category/ … Read more