Skip Navigation

[Resolved] Favouriting behaves incorrectly when zero Job Ads are favourited

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by simonM-5 9 months, 1 week ago.

Assigned support staff: Waqar.

Author
Posts
#2306881

Hi Support

If possible, could this ticket be assigned to Jamal? He worked intensively with us to create our Favourites functionality and wrote the Custom Code snippet necessary to get it working.

We are seeing inconsistent behaviour in our Favourites Views, in particular My Favourite Job Ads View.

Related Custom Code Snippet: "favourites"
Related 3rd party plugin: "WP Favorite Posts"

Issue:
It works for some users, but not for others with the same role. Affected role: Native Nanny.

Correct behaviour:
1) Log in as {login info removed}
2) Click the heart symbol in the menu. Only Job Ads are shown which have been favourited (the favourite heart is solid green).
3) Favouriting more Job Ads under Find a Job continues to show only the favourited ads.
4) Removing all hearts under Find a Job correctly shows zero Job Ads when clicking the Favourites menu (heart symbol). Our customised message for No Ads to show is correcly displayed.
5) This seems to work correctly, regardless of which language the Job Ad was favourited in.

Incorrect behaviour:
1) Log in as {login info removed}:
2) Click the heart symbol in the menu. ALL Job Ads are shown even when no Job Ads have been favourited (although the favourite heart is showing as an empty heart, ie is unfavourited).
3) Favouriting one or more Job Ads under Find a Job shows only the favourited Job Ads.
4) Removing all hearts under Find a Job incorrectly shows ALL Job Ads when clicking the Favourites menu (heart symbol). Our customised message for No Ads to show is NOT displayed, instead ALL Job Ads are displayed.
5) The favouriting appears to be working correctly, regardless of which language the Job Ad was favourited in.

The incorrect behaviour appears to be happening only when zero Job Ads are favourited.

We'd greatly appreciate your help getting this working consistently for all users.

Kind regards
Simon

#2307211

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for contacting us.

Jamal has moved to a different department, so it won't be possible for him to follow up on this.

Looking into the code snippets in the custom code 'favourites', this is expected because when a user has no favorite posts, the "wpfp_get_user_meta()" function returns an empty array.

To overcome this, you can replace the line:


$query_args['post__in'] = wpfp_get_user_meta();

With:


$fav_posts = wpfp_get_user_meta();

if(!empty($fav_posts)) {
	$query_args['post__in'] = $fav_posts;
}
else
{
	$query_args['post__in'] = array('0');
}

This change checks for the favorited posts through the "wpfp_get_user_meta()" function and if it is empty, sets the query to include only an imaginary post with ID '0', which in turn results in no items found message.

regards,
Waqar

#2307237

Good morning Waqar

Oh, didn't realise that about Jamal, please pass on my regards to him and wish him luck in his new role!

I changed that code, and that seems to have fixed it! Thanks so much!

One last thing - can you please edit out the login data in https://toolset.com/forums/topic/favouriting-behaves-incorrectly-when-zero-job-ads-are-favourited/#post-2306881 ? I'm still seeing the login details.

Thanks and kind regards
Simon

#2307249

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that this is fixed.

I've removed the login data from your message and will pass on your regards to Jamal.

You're welcome to mark this ticket as resolved and start a new one, for each new question or concern.

#2307251

My issue is resolved now. Thank you!