Skip Navigation

[Resolved] Display User Favorites in a View using favoriteposts plugin

This thread is resolved. Here is a description of the problem and solution.

Problem:
Display User Favorites in a View using https://favoriteposts.com/ plugin

Solution:
You need to use the view's filter hook "wpv_filter_query" in order to display the favorite posts of current loggedin user using the https://favoriteposts.com/ plugin.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/display-user-favorites-in-a-view/#post-1389493

Relevant Documentation:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 13 replies, has 2 voices.

Last updated by jeleenC 4 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1387611

Hi,

So I was hoping to show my favorites (from this plugin: hidden link) in a Toolset View.

I saw that there's a filter that automatically appears on Views, called simplefavorites_count. However, when I use it to filter posts (simplefavorites_count > 0), the favorites of all users appear on all dashboards (instead of favorites of the current user). Also, it doesn't seem to remove posts when I unfavorite them.

Thanks and looking forward to your response!

#1387797

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please tell me where you see the simplefavorites_count filter? Maybe a screenshot would help.
- Do you want to display all the favorite posts for the current logged-in user?

#1387867
simplefavorites.JPG

Hi Minesh, I uploaded the screenshot of where I find simplefavorites_count and how I set up the filter for it.

The goal is to display favorites of the currently logged in user in a custom View (hopefully exactly the same as the thumbnail View I set up for my custom type).

Thanks!

#1387923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I installed the plugin on my local test install: https://wordpress.org/plugins/favorites/

And I make few favorite posts but with my view, I do not see the custom field you shared in the screenshot.

Can you please share admin access details so I can check this further.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1388469
customize-area.JPG
what-it-looks-like-right-now.JPG
what-it-should-look-like.JPG

Hi Minesh, so I found an alternative solution that might be more straightforward.

Apparently there is an option to customize the display of favorites from the plugin. Maybe this is the better approach so I don't have to rely on Views to do the filtering, the plugin does it.

However, when I paste the template of the loop I currently have, the appearance is still not exactly the same. I have attached screenshots.

Here is the template I have from Toolset views (What it should look like):

<div class="property-thumbnail">
[wpv-post-featured-image size="full"]
  <div class="list-compare-wrapper">
    [favorite_button]<br>
    <label class="compare">
      <input type="checkbox" name="post_ids[]" value="[wpv-post-id]">
      <i class="fas fa-balance-scale" title="Add to Compare"></i>
      </label>
  </div>
  <div class="property-thumbnail-content-wrapper">
	<h6>#[types field="property-id"][/types] | [types field="property-type"][/types] | [wpv-post-taxonomy type="property-location"]</h6>
	<h3>[wpv-post-link]</h3>
	<div class="row">
		<div class="col-sm-6 col-md-6 col-lg-6"><h5>PHP [types field='property-price-text'][/types]</h5>
  			<p>[types field="bedrooms"][/types] Beds  [types field="bathrooms"][/types] Baths  [types field='lot-area'][/types] m<sup>2</sup></p>
    </div>
		<div class="col-sm-6 col-md-6 col-lg-6"><button class="view-black">[wpv-post-read-more label="View Listing"]</button></div>
   </div>
  </div>
</div>

I made adjustments to the shortcodes since the plugin doesn't use the [types...] configuration. Here's what I have so far (What it looks like right now):

<div class="property-thumbnail">
[wpv-post-featured-image size="full"]
  <div class="list-compare-wrapper">
    [favorite_button post_id="[wpv-post-id]"]<br>
    <label class="compare">
      <input type="checkbox" name="post_ids[]" value="[wpv-post-id]">
      <i class="fas fa-balance-scale" title="Add to Compare"></i>
      </label>
  </div>
  <div class="property-thumbnail-content-wrapper">
	<h6>#[types field="property-id"][/types] | [types field="property-type"][/types] | [wpv-post-taxonomy type="property-location"]</h6>
	<h3>[wpv-post-link]</h3>
	<div class="row">
		<div class="col-sm-6 col-md-6 col-lg-6"><h5>PHP [types field='property-price-text'][/types]</h5>
  			<p>[types field="bedrooms"][/types] Beds  [types field="bathrooms"][/types] Baths  [types field='lot-area'][/types] m<sup>2</sup></p>
    </div>
		<div class="col-sm-6 col-md-6 col-lg-6"><button class="view-black">[wpv-post-read-more label="View Listing"]</button></div>
   </div>
  </div>
</div>

Also attached is a screenshot of the area where I paste the favorites layout--there are notes there that might be helpful.

#1388577

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is the custom thing and requires custom adjustment. Maybe its better that you should approach the favorites plugin support and ask them how to customize their layout. Maybe Types shortcode should not be supported within that layout but better you check with the favorites plugin support and ask them how you can integrate those fields.

I see they support some dynamic fields but you need to check with them.

#1389063

Hi Minesh, I already reached out to them but unfortunately they haven't responded. Also, most of the custom fields are already displaying properly (price, beds, baths) so maybe I'm just doing something wrong with the others?

See it here: hidden link

Thanks!

#1389325

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If you can share access details and problem URL and share posts where it works and where the button does not work. I can try to check this further and guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1389419

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Even after login I do not see anything on this page: hidden link

Can you please share the details which I asked in my previous reply:
problem URL and share posts where it works (as per your code) and where the button does not work. I can try to check this further and guide you in the right direction.

#1389435

Hi Minesh, this is the page where the properties are displaying properly: hidden link

My List is supposed to show the favorites when you click on the bookmark icon on a property.

#1389493

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Actually, there was no way to add Types field to your plugin's customization section.

But, fortunately, I found a way to get the favorite posts of the current user.

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_filter('wpv_filter_query', 'func_search_range_within', 99, 3);
function func_search_range_within($query, $setting,$view_id) {
  
    if($view_id == 500) {
        global $current_user;
      	 
        $x =  get_user_meta($current_user->ID,'simplefavorites',true);
 		$res = $x[0]['posts'];
       
         if(!empty($res)){
           $query['post__in'] = $res;
         }else{
             $query['post__in'] = array(0);
         }
       
    }
  
     
    return $query;
}

On the following page: hidden link

I've added the following view and removed the plugin shortcode you added;

[wpv-view name="favorites-view"]

I can see favorite posts displayed correctly. Can you please confirm.

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1389693

Hi Minesh, it works perfectly for logged in users, thank you very much :))

However, I also enabled Favorites for logged out users/guests. Based on the Favorite plugin's doc, this is saved in cookies instead of user meta. Is it possible to capture this in the view as well?

If not (or if it's too complex), I might just disable it for guests.

Otherwise, big thanks and appreciate the help so far :))

#1389803

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - that will require too much investigation and could be complex as well.

#1389933

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.