4

私は wordpress ループを書いていますが、用語が割り当てられていないすべての投稿を取得したいと考えています。それを行う簡単な方法はありますか?それとも、すべての用語 ID を取得して、次のような税クエリを実行する必要がありますか?

// Get all the term id's
$terms = array();
$terms = getAllTheTerms();

// Create an arguments which get all the posts that do not have a term with any
// of the id's.
$args = array(
    'post_type' => 'post',
    'tax_query' =>
        array(
            'taxonomy' => 'actor',
            'field' => 'id',
            'terms' => $terms,
            'operator' => 'NOT IN'
    )
);
$query = new WP_Query( $args );

データベースに関しては、クエリなしですべての投稿を非常に簡単に取得できるため、これはばかげたクエリのように思えます。

4

3 に答える 3

3
$terms = get_terms( $taxonomy, array('fields'=>'ids')); /* GET ALL TERMS FROM A TOXNOMY */
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => $taxonomy,
            'field'    => 'term_id',
            'terms'    => $terms,
            'operator' => 'NOT IN' /* DO THE MAGIC -  Get all post that no in the taxonomy terms */
        )
    )
);
$the_query = new WP_Query( $args );
于 2015-11-19T14:04:48.280 に答える
1

あなたはこれを試すことができます

$args = array(
    'post_type' => 'post',
    'tax_query' =>
        array(
            'taxonomy' => 'actor',
            'field' => 'slug',
            'terms' => '',
    )
);
$query = new WP_Query( $args );
于 2013-10-04T20:51:52.287 に答える