Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Role Scoper interferes with query

UserPost

7:44 am
December 3, 2009


monkeyangst

Member

posts 4

1

Hello all,

I'm very intrigued by the Role Scoper plugin. I maintain a plugin which allows WordPress to be used for webcomics, and I think RS would be ideal for adding the capability to allow certain comics only to be seen by certain members — such as people who've paid for the privilege.

However, I am seeing a conflict. Out of the box, with no custom settings, RS interferes with a custom query my plugin does at the top of the index page. Basically, it creates a custom WP_Query object to find the latest post in the Comics category. This object is then used by most of my other functions throughout the page.

The query string generated is:

&cat=3,&showposts=1&caller_get_posts=1&orderby=date&order=ASC

This is the SQL that WordPress uses when this query is working properly:

SELECT SQL_CALC_FOUND_ROWS  stripshow_posts.* FROM stripshow_posts
INNER JOIN stripshow_term_relationships ON (stripshow_posts.ID =
stripshow_term_relationships.object_id) INNER JOIN
stripshow_term_taxonomy ON
(stripshow_term_relationships.term_taxonomy_id =
stripshow_term_taxonomy.term_taxonomy_id)  WHERE 1=1  AND
stripshow_term_taxonomy.taxonomy = 'category'  AND
stripshow_term_taxonomy.term_id IN ('3')  AND stripshow_posts.ID NOT IN
( SELECT tr.object_id FROM stripshow_term_relationships AS tr INNER JOIN
stripshow_term_taxonomy AS tt ON tr.term_taxonomy_id =
tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN
('0') ) AND stripshow_posts.post_type = 'post' AND
(stripshow_posts.post_status = 'publish' OR stripshow_posts.post_status
= 'private') GROUP BY stripshow_posts.ID ORDER BY
stripshow_posts.post_date ASC LIMIT 0, 1

But here is the SQL I see when RS is activated:

SELECT SQL_CALC_FOUND_ROWS DISTINCT stripshow_posts.* FROM
stripshow_posts INNER JOIN stripshow_term_relationships ON
(stripshow_posts.ID = stripshow_term_relationships.object_id) INNER JOIN
stripshow_term_taxonomy ON
(stripshow_term_relationships.term_taxonomy_id =
stripshow_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND
stripshow_term_taxonomy.taxonomy = 'category' AND
stripshow_term_taxonomy.term_id IN ('3') AND stripshow_posts.ID NOT IN
('56', '57', '58', '59', '60', '61', '62', '63') AND
stripshow_posts.post_type = 'post' AND (stripshow_posts.post_status =
'publish' OR stripshow_posts.post_status = 'private') GROUP BY
stripshow_posts.ID ORDER BY stripshow_posts.post_date ASC LIMIT 0, 1

I'm certain I can work around this, but I cannot figure out why these posts are being excluded. The NOT IN clause of the query includes all the posts that are in the category I'm specifying, but not other posts. I cannot figure out why RS modifies the query to exclude the category I want to include.

12:47 am
December 4, 2009


Kevin

Admin

posts 2381

2

For now, I'm going to suggest an ugly workaround and add better subselect parsing to my ToDo list.

$custom_query = new WP_Query( 'your_query_string&suppress_filters=1' );

global $wp_query;
$buffer_var = $wp_query->query_vars['category__not_in'];
$wp_query->query_vars['category__not_in'] = $custom_query->query_vars->query_vars['category__not_in'];

$custom_query = new WP_Query( 'your_query_string' );

$wp_query->query_vars['category__not_in'] = $buffer_var;

Also keep in mind that the suppress_filters argument is a solution in itself if you just want to prevent Role Scoper from modifying your query at all.

8:59 am
December 4, 2009


monkeyangst

Member

posts 4

3

Thanks for the quick reply! I've applied the suppress_filter option and it works fine. I'll look into the remainder of your suggestion when I get a chance, as applying RS's filters would be a good thing — if it filtered out posts to which a particular user has no access (for example, because they haven't paid), this would open up a world of possibilities for my users.


About the Agapetry forum

Currently Online:

16 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1181

Posts: 5363

Members:

There are 1173 members

There are 1 guests


Kevin has made 2381 posts

Top Posters:

metal450 - 148

Ragnar - 102

YikYak - 68

whiteorb - 44

Daisy - 35

Administrator: Kevin | Moderators: Kevin