Frage

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>
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top