Favorites is a WordPress plugin designed for end users and theme developers. It provides an easy-to-use API for adding favorite button functionality to any post type.
The plugin name is “Favorites,” but the button text is customizable. It can provide a way to save favorites, likes, bookmarks, or any other similar types of data.
composer install
The favorite button can be added automatically to the content by enabling specific post types in the plugin settings. It may also be added to template files or through the content editor using the included functions or shortcodes. The post id may be left blank in all cases if inside the loop. The site id parameter is optional, for use in multisite installations.
get_favorites_button($post_id, $site_id)
the_favorites_button($post_id, $site_id)
[favorite_button post_id="" site_id=""]
Total favorites for each post are saved as a simple integer. If a user unfavorites a post, this count is updated. Anonymous users' favorites count towards the total by default, but may be disabled via the plugin settings. The post id may be left blank in all cases if inside the loop.
get_favorites_count($post_id)
the_favorites_count($post_id)
[favorite_count post_id=""]
Displays the total number of favorites a user has favorited. Template functions accept the same filters parameter as the user favorites functions.
get_user_favorites_count($user_id, $site_id, $filters)
the_user_favorites_count($user_id, $site_id, $filters)
[user_favorites user_id="" site_id="" post_types=""]
Displays the total number of favorites across an entire site.
get_total_favorites_count($site_id)
the_total_favorites_count($site_id)
User favorites are stored as an array of post ids. Logged-in users' favorites are stored as a custom user meta field, while anonymous users' favorites are stored in either the session or browser cookie (configurable in the plugin settings). If the user id parameter is omitted, the favorites default to the current user. The site id parameter is optional, for use in multisite installations.
get_user_favorites($user_id, $site_id, $filters)
get_user_favorites_list($user_id, $site_id, $include_links, $filters, include_thumbnails="false" thumbnail_size="thumbnail" include_excerpt="false")
the_user_favorites_list($user_id, $site_id, $include_links, $filters, include_thumbnails="false" thumbnail_size="thumbnail" include_excerpt="false")
[user_favorites user_id="" include_links="true" site_id="" post_types="", include_thumbnails="false" thumbnail_size="thumbnail" include_excerpt="false"]
The clear favorites button clears out all of the current user's favorites.
get_clear_favorites_button($site_id, $button_text)
the_clear_favorites_button($site_id, $button_text)
[clear_favorites_button siteid="" text=""]