Support Forum
Support › Meta Box - Beaver Themer Integrator › Posts module bug when listing favorites
Hi there
When displaying a user's MB favorites in a Beaver Builder posts module, if they have no favorites, then it defaults to show all posts. But it should show none.
As soon as they have one favorite marked then it only shows one. But if you unfavorite that, then it goes back to showing all posts.
It should show no posts when the users has no favorites.
Can this please be resolved?
Thanks
Hello,
The "user's MB favorites" is a table that shows the list of user's favorite posts, how do you use this with the Beaver posts module? Please share a screen record of those steps so I can reproduce the issue on my demo site.
I forgot how I did this, sorry. But it was actually by just using the main query in the Beaver Builder posts module, and modifying that query via functions.php using this, which I assume I got from your site:
function tas_not_listened_fl_builder_loop_query_args_filter( $query_args ) {
if ( 'tas-metabox-not-listened' == $query_args['settings']->id ) {
$user_id = get_current_user_id();
$post_ids = get_user_meta( $user_id, 'mbfp_posts', true );
if ( ! empty( $post_ids ) ) {
$query_args['post__not_in'] = $post_ids; // Exclude the post IDs
}
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'tas_not_listened_fl_builder_loop_query_args_filter' );
Hello,
- As soon as they have one favorite marked then it only shows one
- It should show no posts when the users has no favorites.
You can change this logic code
if ( ! empty( $post_ids ) ) {
$query_args['post__not_in'] = $post_ids; // Exclude the post IDs
}
to
if ( ! empty( $post_ids ) ) {
$query_args['post__in'] = $post_ids; // Include the post IDs
} else {
$query_args = [];
}
however, I see it is the standard behavior of the shortcode [mbfp-posts]
without any difference. Please follow the documentation https://docs.metabox.io/extensions/mb-favorite-posts/#shortcodes
And please notice that, supporting the custom code is beyond our scope of support. If you have any issues with the code, you can contact an expert developer to help you or contact us here https://metabox.io/contact/. We offer a customization service with an extra fee.