How to add a button to remove the post from the list of favorite post?
I have created a client’s website where I added the functionality that logged in user can mark the articles as its favorite for that I’m using favorites for WordPress plugin.
I did this by creating a shortcode where I tried to get ID’s of favorite marked post
and display favorite posts accordingly.
function custom_favorites_list_thumbnail()
{
$filters = array(
'post_type' => array('articles'
)
);
$fav = get_user_favorites($user_id = null, $site_id = null, $filters = $filters);
if($fav){
$ids = implode(', ', $fav);
}
else {
$ids = "";
}
//var_dump($ids);
//$view_fav = "[wpv-view name='view-for-favorite-post-image' ids='". $ids ."']";
return $ids;
}
add_shortcode('favorite_articles_id', 'custom_favorites_list_thumbnail');
It is working fine.
But what I want now I want to add a button to each favorite post so that the user can click that button and post will be removed from its list of favorite posts.
I tried that by using the shortcode “[clear_favorites_button]” and function the_clear_favorites_button($site_id = null, $text = null);
, but that removed all post from the list.This is not the solution for what I m looking for.
I guess this should be done when I get only that particular post ID and add some function to remove that post-filter by post ID.
Help if anyone knows the solution.
Thanks.
Leave an answer