Php Wordpress-如何使用';类别不在';在wp_查询中

Php Wordpress-如何使用';类别不在';在wp_查询中,php,wordpress,Php,Wordpress,我有个小问题。 我试图从某些自定义帖子类型中检索所有帖子,不包括类别ID78中标记的帖子 我有两个职位。 一个仅标记为78类,另一个未标记为78类。 我查看了一些老帖子,比如,但对我来说,它不起作用。 我看到了所有的结果 这是我的代码: function data_fetch(){ $the_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ),

我有个小问题。 我试图从某些自定义帖子类型中检索所有帖子,不包括类别ID78中标记的帖子

我有两个职位。 一个仅标记为78类,另一个未标记为78类。 我查看了一些老帖子,比如,但对我来说,它不起作用。 我看到了所有的结果

这是我的代码:

 function data_fetch(){

    $the_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => 'article', 'category__not_in ' => array( 78 ) ) );
    if( $the_query->have_posts() ) :
        while( $the_query->have_posts() ): $the_query->the_post(); ?>

            <h2><a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a></h2>

        <?php endwhile;
        wp_reset_postdata();
    endif;

    die();
}
我做错了什么?

试试这个:

function data_fetch(){
$args = array( 'posts_per_page' => -1, 
                's' => esc_attr( $_POST['keyword'] ), 
                'post_type' => 'article', 
                'tax_query' => array(
                        array(
                            'taxonomy' => 'audience',
                            'field'    => 'term_id',
                            'terms'    => array( 78 ),
                            'operator' => 'NOT IN',
                        ),
                    ), 
                );
    $the_query = new WP_Query($args);
    if( $the_query->have_posts() ) :
        while( $the_query->have_posts() ): $the_query->the_post(); ?>

            <h2><a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a></h2>

        <?php endwhile;
        wp_reset_postdata();
    endif;

    die();
}
函数数据_fetch(){
$args=数组('posts\u per\u page'=>-1,
's'=>esc_attr($\u POST['keyword']),
“post_type”=>“article”,
“tax_query”=>数组(
排列(
“分类法”=>“受众”,
'field'=>'term_id',
“术语”=>数组(78),
'运算符'=>'不在',
),
), 
);
$thew_query=newwp_query($args);
如果($the\u query->have\u posts()):
while($the_query->have_posts()):$the_query->the_post();?>
试试这个:

function data_fetch(){
$args = array( 'posts_per_page' => -1, 
                's' => esc_attr( $_POST['keyword'] ), 
                'post_type' => 'article', 
                'tax_query' => array(
                        array(
                            'taxonomy' => 'audience',
                            'field'    => 'term_id',
                            'terms'    => array( 78 ),
                            'operator' => 'NOT IN',
                        ),
                    ), 
                );
    $the_query = new WP_Query($args);
    if( $the_query->have_posts() ) :
        while( $the_query->have_posts() ): $the_query->the_post(); ?>

            <h2><a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a></h2>

        <?php endwhile;
        wp_reset_postdata();
    endif;

    die();
}
函数数据_fetch(){
$args=数组('posts\u per\u page'=>-1,
's'=>esc_attr($\u POST['keyword']),
“post_type”=>“article”,
“tax_query”=>数组(
排列(
“分类法”=>“受众”,
'field'=>'term_id',
“术语”=>数组(78),
'运算符'=>'不在',
),
), 
);
$thew_query=newwp_query($args);
如果($the\u query->have\u posts()):
while($the_query->have_posts()):$the_query->the_post();?>


你能指定帖子类型和分类类型吗?你是说自定义帖子类型初始化代码吗?好的,让我看看,我可以看到帖子类型是文章,但我需要类别类型(这篇帖子是标记为默认类别还是分配给某个自定义分类?)
'category\uu not\u in'
需要是
'category\uu not\u in'
删除额外空间there@Yamu是的。但是在
中的
和那里的
之间删除多余的空格。
我已经编辑了我的评论,然后你说可以指定帖子类型和分类类型吗?你是说自定义帖子类型初始化代码吗?好的,让我看看,我可以看到文章类型是article,但我需要类别类型(这篇文章是标记为默认类别还是分配给某个自定义分类法?)
'category\uu not\u in'
需要是
'category\uu not\u in'
删除额外空间there@Yamu是的。但是在
中的
和那里的
之间删除多余的空格。
在你说之前,我已经编辑了我的评论。对不起,仍然得到了所有的帖子…我重复了检查,cat id是正确的…有什么可以证明的?在你的帖子类型初始化中代码,我可以看到您正在尝试为文章注册分类法“category”。category是默认保留的分类法,请将其更改为其他分类法。是否可以登录到后端并显示类别id为78(您要排除的类别id)的url发现错误。分类法不是类别,而是受众。您的代码是正确的。谢谢!!!很高兴我能提供帮助。干杯!!抱歉,仍然收到所有帖子…我重复了检查,cat id是正确的…有什么原因?在您的帖子类型初始化代码中,我可以看到您正在尝试为文章注册分类法“类别”。类别是de错误保留分类法,将其更改为其他分类法。您是否可以登录到后端并显示类别id为78(您要排除的类别id)的url发现错误..分类法不是类别,而是受众。您的代码是正确的。谢谢!!!很高兴我能帮上忙。干杯!!