MB Favorite Posts in Bricks

MB Favorite Posts is an add-on plugin for users of Meta Box lifetime bundle that enables your site’s visitors and logged-in users to mark posts as favorites.

This Pro tutorial explores using MB Favorite Posts in Bricks, including outputting the list of favorites via a query loop.

The plugin provides a shortcode for showing user’s (logged-in or visitor) favorites:

[mbfp-posts]

If you want to use a Bricks query loop for showing the list of favorites (regardless of whether the user is logged-in or not), turn on the Query editor (PHP) for the query-loop enabled item (typically, a Block element) and paste:

$favorites = ! empty( $_COOKIE['mbfp_posts'] ) ? json_decode( $_COOKIE['mbfp_posts'] ) : [];

if ( is_user_logged_in() ) {
	$favorites = get_user_meta( get_current_user_id(), 'mbfp_posts', true );
}

$favorites = (array) $favorites;

return [
	'post__in' => $favorites,
 	'posts_per_page' => -1,
];

Note: There is no simple/straightforward way to set up delete buttons for each post in the query loop. If that is needed, you are advised to use the shortcode.

References

/wp-content/plugins/Meta Box/mb-favorite-posts/src/Helper.php