Bricks Builder query loop filter to show CPT posts from logged in users
Both the following codes work. Add the snippet in theme’s function.php file.
// Bricks query filter to show only posts from logged in users
// Replace 'bricksContainerId' with container id of query loop. Example: if container id is #brxe-abcxyz, use 'abcxyz'
// Replace 'post-type-slug' with your CPT slug
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( $element_id == 'bricksContainerId' && is_user_logged_in() ) {
$query_vars['post_type'] = [ 'post-type-slug' ];
$query_vars['author'] = get_current_user_id();
}
return $query_vars;
}, 10, 3 );
// Bricks query filter to show only posts from logged in users
// Replace 'bricksContainerId' with container id of query loop. Example: if container id is #brxe-abcxyz, use 'abcxyz'
// Replace 'post-type-slug' with your CPT slug
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( $element_id !== 'bricksContainerId' ) {
return $query_vars;
}
if ( $user_id = get_current_user_id() ) {
$query_vars['post_type'] = 'post-type-slug';
$query_vars['author'] = $user_id;
}
return $query_vars;
}, 10, 3 );
Reference: