I have a small problem when attempting to query some posts by author. I have events and registrations. Currently I have 4 registrations, all created by User2 with the wp-admin showing that correctly. If I run the following code with a user logged on it works. User2 shows all and User1 shows none. However, if no-one is logged on it returns all of the registrations. The user_id is being shown as 0 so it shouldn't find any of the registrations but it finds all of them, those for user 1 and those for user 2. Is there anyway I could stop this without having to check is_user_logged_in() each time.
Thanks
$reg_count=0;
//if (is_user_logged_in()){
echo "looking for registrations with author id of " . get_current_user_id();
$registrations = new WP_Query(Array(
'posts_per_page' => -1,
'post_type' => "registration",
'author' => get_current_user_id(),
'meta_key' => 'first_name',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key'=> 'event_id',
'compare' => 'LIKE',
'value' => '"' . get_the_id() . '"'
)
)
));
$reg_count = $registrations->found_posts;
echo "found " . $reg_count . " registrations wih author id of " . get_current_user_id();
//}
?>