Thursday, June 9, 2022
HomeWordPress DevelopmentExclude taxonomy Question if post_type

Exclude taxonomy Question if post_type


How can I outline in pre_get_posts hook on customized publish kind to not execute the question on a taxonomy.

I’ve the next

if (!empty($newsType) && $newsType == 'press') {
    //if $newsType exclude the taxonomy question and get simply the post_type
    $taxQuery = [
        [
            'taxonomy' => 'news_type',
            'operator' => 'NOT IN',
        ]
    ];

    $this->query->set('post_type', ['press']);
    $this->query->set( 'tax_query', $taxQuery );

} else {
    $this->query->set('post_type', ['news', 'press']);
}

$newsType is the $_GETvariable from request

If I do the next
unset($this->query->query_vars['news_type']); the question will break with

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments