Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




get_posts not returning posts with permission?

UserPost

10:21 am
December 18, 2008


metal450

Member

posts 178

1

Role Scoper seems to now be working perfectly, and doing exactly what I'd hoped…with just ONE exception :)


If I list my posts via The Loop, things work fine and it displays what it's supposed to.

However, if I try to grab the posts with get_posts(), it doesn't seem to return any that are marked as Private (even though I should be able to view them according to the permissions I've set, and can view them in The Loop).


In case you're wondering, what I'm trying to do is to find out if the current user is able to view ANY of the posts given a certain criteria…for example:

$thePosts = get_posts('numberposts=1&category=24);

if ( count($albums) == 0 ) {/*Could the user see any posts under category 24?*/}

3:02 pm
December 23, 2008


Kevin

Admin

posts 2503

2

Things you should know about the WordPress function get_posts():

  • It forces published status unless you pass in a post_status argument
  • There is no option to return both published and private posts
  • It bypasses query filtering (such as Role Scoper's) unless you pass in suppress_filters=0
  • In WP 2.5 and earlier, query filtering is always bypassed

Of course, it's possible to call get_posts() separately for publish and private status, and combine the results. To keep your theme code simpler, I would call WP_Query::query directly instead:

$scoper->query_interceptor->skip_teaser = true; $temp_query = new WP_Query;

$cat_id = 0; // set to pertinent value $first_readable_cat_post = $temp_query->query("cat=$cat_id&posts_per_page=1″);

$scoper->query_interceptor->skip_teaser = false;

Of course, this is only necessary if your site is using the Hidden Content Teaser for posts. Without the skip_teaser setting, you would have to walk through the return array and manually disregard and posts with the scoper_teaser property set true.

Note, though that the skip_teaser setting will not be effective with Role Scoper <= 1.0.0 RC5b unless you add the following line at the top of function _get_teaser_object_types in query_interceptor_rs.php:

if ( ! empty($this->skip_teaser) ) return array();

About the Agapetry forum

Currently Online:

15 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1246

Posts: 5654

Members:

There are 1257 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin