Last active
May 18, 2023 13:34
-
-
Save zackpyle/f8c8f7d8339377358484bc431f4a9ff3 to your computer and use it in GitHub Desktop.
Only show current user's posts in BB post module #beaverbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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