循环访问只有2个状态的帖子

时间:2021-05-13 作者:DCEXC

为小部件设置可见性条件-我需要它应用于特定术语中的帖子,但仅适用于;“待定”;和;“发布”;地位这实际上隐藏了;添加新帖子;按钮,如果他们在该期限内已经有一篇待处理或已发布的帖子。我只是无法正确定义这两种状态。我只能定义1,它工作得很完美。

$type = \'my_cpt\';
$tax = \'my_tax\';
$term_name = \'my_term\';
$term_id = 133;

    $args = array(
        \'post_type\'             => $type,
        \'author\'                => get_current_user_id(),
            \'post_status\' => array( \'pending\', \'publish\' ),
        \'tax_query\' => array(
            array(
            \'taxonomy\'      => $tax,
            \'field\'         => $term_name,
            \'terms\'         => $term_id,
            \'include_children\'  => false
            )
        )
    );
        
        $jobs = get_posts( $args );
        
        if(count($jobs) >= 1){?>
        
        <center>
            <?php echo ("You currently have ".count($jobs)." active Final Submission. Please delete it to add another one.");
            return true;
        }?>
        </center>

1 个回复
最合适的回答,由SO网友:Klian 整理而成

您是否尝试过;post\\U状态“;而不是;“状态”;正如文件所述:https://developer.wordpress.org/reference/classes/wp_query/#status-parameters ?