0

I'm using the below code to try to return the count of custom post types but the query isn't finding anything. I change the post_type to project and it works fine. This is also being used outside of the loop if that makes a difference?

 function get_user_posts_count($user_id, $post_type) {
    $args['author']     = 1;
    $args['post_type']  = 'project';
    $args['posts_per_page'] = -1;
    $args['post_status']    = 'any, trash';

    $ps = new WP_Query( $args );

    echo var_dump ($ps);

}

1 Answer 1

1

WP_Query does not accept a comma delimited string for the post_type argument, it must be one of either a string (for one post_type) or an array (for one-or-more post_type).

$args = array(
    'post_type' => 'post'
);

$query = new WP_Query($args);

OR

$args = array(
    'post_type' => 
    array(
        'post'
    )
);

$query = new WP_Query($args);

OR

$args = array(
    'post_type' => 
    array(
        'post',
        'page',
        'movie',
        'book'
    )
);

$query = new WP_Query($args);

Useful reading:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.