List taxonomy Terms related to specific post_type Wordpress

Asked

Viewed 507 times

0

Hello, I have to list all Terms of 4 taxonomies, however they have to belong to a specific post type!

For example, I have the following information:

post_type ( graduation, pos_graduation ) taxonomy (place, unit)

I’ve searched everywhere, and I can’t find what I’m looking for..

I want to list all the terms that have post marked as taxonomy: place and that belong to undergraduate; I tried get_terms, wp_get_post_terms, did several tests and loops and none brought me the list I need.

If you can help me, I really appreciate it! Obs. taxonomies are related to all post types.

2 answers

0

I believe you need to do the consul for tax_query

$posts = get_posts(
    array(
        'posts_per_page' => -1,
        'post_type' => 'graduacao',
        'tax_query' => array(
            array(
                'taxonomy' => 'nome-taxonomia', //o nome da sua taxonomia
                'field' => 'term_id', // id do campo da taxonomia...
                'terms' => 'local', // o termo da taxonomia
            )
        )
    )
);

I’m considering that local is an item within a taxonomy called nome-taxonomia

  • Actually no, I need to list all the terms, for example, with get_terms I can bring all the registered terms of all the taxonomies and make a select. Fine... I just can’t pull all these terms on the post type I want.. Got it? I need him to bring me a list of terms related to the specific post type

  • The tax_query I use to bring terms-specific posts, in this case, is almost the other way around.. rs bring all and only the terms of the specific post_type

  • you came to see the function get_object_taxonomies, apparently does what you want. That I have not tested...

  • Tentei algo como: 

 global $post;
 $loop = new WP_Query(array('post_type' => 'pos_graduacao', 'posts_per_page' => -1));
 while ($loop->have_posts()) : $loop->the_post();
 $terms = wp_get_post_terms($post->ID, $nd_learning_tax); he even brings some, but he doesn’t bring all the terms that refer to the post type.. rs Difícil

  • get_terms in general without arguments.. I tested almost all and tbm did not work

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.