Resources

My Agape try

Your Agape try


Support Forum

Current User: Guest Login Register
Please consider registering

Search 
Search Forums:


 




get_posts not returning posts with permission?

UserPost

10:21 am
December 18, 2008


metal450

Member

posts 98

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 1385

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();


Reply to Topic: get_posts not returning posts with permission?

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 11 + 6        (Required)

Topic Reply:


 

About the Agapetry forum

Currently Online:

jgilles

8 Guests

Maximum Online: 88

Forums:

Groups: 2

Forums: 7

Topics: 703

Posts: 3189

Members:

There are 640 members

There are 1 guests


Kevin has made 1385 posts

Top Posters:

metal450 - 98

YikYak - 58

Ragnar - 36

Daisy - 35

victar - 33

Administrator: Kevin | Moderators: Kevin