Urban Giraffe Support | Plugins
userpermission parameter for query_posts() function?
Hi.
I usually show up 2 posts on my first page. Even if the user is logged in or not.
So if the user is a non-registered user only posts without any permissions will
be shown to him.
In the index.php I use the following code to limit the query to two posts.
1. without userpermissions)
//limit query to show 2 posts on first page
query_posts('posts_per_page=2');
//loop
if (have_posts()) :
while (have_posts()) : the_post();
[...]
endwhile;
[...]
2. with userpermissions)
//limit query to show 2 posts on first page
$count=0;
global $current_user;
//loop
if (have_posts()) :
while (have_posts()&&$count<=1) : the_post();
$permissions = Permissions::get ($post->ID);
if ($permissions->can_read ($current_user) == true){
[...]
$count++;
};
endwhile;
[...]
Question: Is there an easier way as I use in 2.) to get all posts in the query
with read permissions to the current user? Maybe there's a parameter to add in
the query_posts() function? So please let me know.
Thanks in advance.
Greetings.
Frank
Responses
Posted 3 months ago by Key Master
I'm surprised you need to add any special code at all as the plugin should hook into the standard WP query function and will remove any posts that you are not allowed to see. This should mean that whatever method is used to display posts will be affected. Have you tried it without the extra code?
Reply
You must log in to post.