Loop through posts of only 2 statuses

Setting up a visibility condition for a widget – i need it to apply to the posts in a certain term but only those of “pending” and “publish” status. this essentially hides the “add new post” button if they already have a post in that term that is pending or published. i just cant define the 2 statuses properly. i can define just 1 and it works perfect.

$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>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Have you tried with “post_status” instead of “status” as documentation says: https://developer.wordpress.org/reference/classes/wp_query/#status-parameters ?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x