Support » Fixing WordPress » Private posts don’t appear when post_type is array in WP_query

  • Hi,

    I’m not sure if there’s something in my theme’s functions.php file causing this problem, but from all the testing I’ve done, I don’t think so. Hopefully somebody else can reproduce this issue:

    When I use WP_Query to query posts while logged in as administrator, any posts set to ‘private’ only appear if ‘post_type’ is EITHER:
    1. left out of the args completely
    2. set to a single string like ‘post’
    3. set to an array with a single item like array(‘post’)

    If it’s set to an array of multiple types e.g.: array(‘post’, ‘page’) then ‘private’ posts disappear completely from the site. I can only get them back by manually setting ‘post_status’ in the args as well, e.g. to: array(‘publish’, ‘private’)

    I’ve scoured docs and references and forums for hours, and can’t find this issue anywhere. Can anybody help?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Kyle Duncan


    I’ve found the problem, but not sure how to fix it…

    In /wp-includes/class-wp-query.php, line 2269, the $read_private_cap variable is set to ‘read_private_multiple_post_types’ because there’s an array of post types in the query. This isn’t a real capability registered with WordPress, so it always defaults to ‘false’ on line 2357, which is why private posts do not appear in results for logged in users when the query has an array of post_types set.

    Is this a bug or an intended feature?

    Thread Starter Kyle Duncan


    For now, I’m fixing this by adding this capability to all users above subscriber:

    $role = get_role(‘contributor’);
    $role = get_role(‘author’);
    $role = get_role(‘editor’);
    $role = get_role(‘administrator’);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Private posts don’t appear when post_type is array in WP_query’ is closed to new replies.