• Resolved fredhead

    (@fredhead)


    I have Role Scoper working fine until I add a query_posts on my index.php template so that page includes all my custom post types. Is there a way to either avoid nuking my RS effects (the index.php page displays data correctly until I add my CPTs with query_posts) or update the query_posts so it also runs/re-runs RS filters?

    Here is my code in the index.php file:

    <?php if ( have_posts() ) :
    	query_posts(array('post_type' => array('post', 'article', 'document', 'faq')));
    ?>

    As you can see, it’s plain vanilla. But adding it causes the page to ignore any RS filters.

    Put another way, is there any way to use query_posts and the category equivalent (the WordPress function that generates category lists) to manually add RS filters?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter fredhead

    (@fredhead)

    Sorry it took so long to work through issues. Here’s what I found in the event someone has a similar problem where use of query_posts makes Role Scoper not work on a WordPress home page.

    The use of query_posts supersedes the WP_Query that builds every WordPress page. Therefore, any special Role Scoper changes to WP_Query or the results of WP_Query also are discarded when query_posts is used. You get a blank slate, all results unfiltered by RS groups.

    In my functions.php file, I updated the WP_Query to display all data from my custom post types:

    function add_custom_post_types( $request ) {
        $home_query = new WP_Query();  // the query isn't run if we don't pass any query vars
        $home_query->parse_query( $request );
    
     	//add content types only if on home page
    	if ($home_query->is_home())
    		$request['post_type'] = array('post', 'article', 'document', 'faq', 'video');
    
        return $request;
    }
    add_filter( 'request', 'add_custom_post_types' );

    This code is a straight modification of code here in the Codex:

    http://codex.wordpress.org/Plugin_API/Filter_Reference/request

    I modified the code to add an array of all my custom post types as the value for $request[‘post_type’] = assignment.

    Finally, to fully make RS work on my site, I removed the category links (because I could not sync up categories and roles, and didn’t really need to bother) to prevent readers from clicking to content they should not see (if someone forgot to restrict content to a group) or blank pages. I also updated my navigation links to display links based on specific groups using the method Kevin documents here:

    http://wordpress.org/support/topic/role-scoper-conditional-data-display-functions

    So now RS works very well. Thank you Kevin for all your hard work creating the plugin!

Viewing 1 replies (of 1 total)
  • The topic ‘Role Scoper: updating query_posts’ is closed to new replies.