Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active May 18, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/f8c8f7d8339377358484bc431f4a9ff3 to your computer and use it in GitHub Desktop.
Save zackpyle/f8c8f7d8339377358484bc431f4a9ff3 to your computer and use it in GitHub Desktop.
Only show current user's posts in BB post module #beaverbuilder
<?php //ignore - only for gist formatting
// Only show current user's posts in BB post module with current-user as module ID
function showAuthorPosts( $query_args ) {
if ( 'current-user' == $query_args['settings']->id ) { // Set the id of the post module to current-user
$query_args['author'] = get_current_user_id(); // Filter by the current logged-in user
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'showAuthorPosts' );
<?php //ignore - only for gist formatting
// Only show current user's posts in BB post module with current-user-not-admin as module ID - but show all for admins
function showAuthorPostsExcludingAdmin( $query_args ) {
if ( 'current-user-not-admin' == $query_args['settings']->id ) { // Set the id of the post module to current-user-not-admin
$current_user = wp_get_current_user(); // Get the current user object
if (!in_array('administrator', $current_user->roles)) { // Check if the user is not an admin
$query_args['author'] = get_current_user_id(); // Filter by the current logged-in user
}
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'showAuthorPostsExcludingAdmin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment