WordPress.org

Ready to get started?Download WordPress

Forums

Role Scoper
[resolved] query_posts not working because of Role Scoper (4 posts)

  1. rockvilla
    Member
    Posted 1 year ago #

    I am using query_post to get few posts of some author, the code is like this,

    query_posts(array(
            'author' => $author_id,
            'paged' => $paged,
            'posts_per_page' => $posts_per_page,
            'post_status' => 'publish',
        ));

    The function having this query is registered as follows:

    add_action('wp_ajax_infinite_scroll', 'wp_infinitepaginate');
    add_action('wp_ajax_nopriv_infinite_scroll', 'wp_infinitepaginate');

    For admin this query works properly. But for not logged in users, php function having this query gets executed but the query returns empty array.

    If I disable 'Role Scoper' the query_posts works for not logged in users also. How can I fix this problem

    Query function : http://pastebin.com/eiVKLf5t
    Ajax Call : http://pastebin.com/q2VjFBhK

    http://wordpress.org/extend/plugins/role-scoper/

  2. vicentt
    Member
    Posted 1 year ago #

    same issue here
    The output of query if rolescoper is active is:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'consejo' AND (( ( ( ( ( 1=2 ) ) ) ) AND wp_posts.post_status = 'publish' )) ORDER BY wp_posts.post_date DESC LIMIT 0, 9

    The condition 1=2 makes that no post are return...

  3. kevinB
    Member
    Plugin Author

    Posted 11 months ago #

    Since you are using Ajax, there is no way for Role Scoper to "know" that the result set should be all readable posts or all editable posts. Of course I have to default to all editable posts.

    Sometime determining the appropriate post type is also problematic. You can change your call to:

    query_posts(array(
            'author' => $author_id,
            'paged' => $paged,
            'posts_per_page' => $posts_per_page,
            'post_status' => 'publish',
            'post_type' => 'your_post_type',
            'required_operation' => 'read',
        ));
  4. kevinB
    Member
    Plugin Author

    Posted 11 months ago #

    Actually, the required_operation arg will not be effective until Role Scoper 1.3.62.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic