Looking to limit the posts in a Bricks query loop to those authored by the currently logged-in user?
Click the query icon for the query loop, enable PHP editor and paste:
if ( is_user_logged_in() ) {
return [
'post_type' => 'post', // change this to your post type
'posts_per_page' => 100, // a large number
'no_found_rows' => true,
'author' => get_current_user_id(),
];
} else {
return [
'post__in' => [ 0 ],
];
}
Click the Sign code button.
You may want to apply a query_results_count
dynamic data condition on the containing parent Section of this query loop-enabled Block to ensure that the entire section is output only if there is at least 1 post.
where mjomxr
is the Bricks ID of the query loop-enabled element.
This means the Section won’t be rendered for users who are not logged in and for users who have not published (authored) any posts of the specified post type.