0

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.

0

Can you do something like [clear_favorites_button post_id="CURRENT_POST_ID"]?

You'll need to edit the [wpv-view] shortcode too.

| improve this answer | |
  • Hi Md Shihab Uddin, I tried this too but this shortcode removed all the posts. I tried [clear_favorites_button post_id="839"] ''839" the particular post id instead of removing that post this shortcode removed all posts. I added this shortcode in my [wpv-view] which is filtered by posts with IDs set by the View shortcode attribute "ids". – Suraj Mar 11 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.