Forums

How to get all posts within one taxonomy and any term (1 post)

  1. egorpromo
    Member
    Posted 8 months ago #

    I have one not resolved problem. There is one way to get posts within one term of taxonomy:

    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'person',
                'field' => 'slug',
                'terms' => 'bob'
            )
        )
    );
    $query = new WP_Query( $args );

    But if I don't know any term of this taxonomy ('person')? I want to get posts that have taxonomy 'person' and any term either 'bob' or 'jim' or somebody else.

    Code below is not working.

    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'person'
            )
        )
    );
    $query = new WP_Query( $args );

    I don't know it is real or not to get posts in that way. I have an idea to get all terms of that taxonome and then get all posts. But maybe more elegant decision exists. Advise me corect code to do it. Thanks!

Reply

You must log in to post.

About this Topic