Let me reply here about (2) and I'll be posting my reply about (1) on the other ticket.
The issue happened after you have changed the function get_duplicates to create both functions get_nanny_ad_duplicates and get_job_ad_duplicates. The function get_duplicates did not exist anymore and caused errors.
I took a new Duplicator copy and worked on it locally to fix that, so I introduced a check on the post type to use the relevant function, by updating these two functions in the "favourites" snippet:
Please replace only these two functions, and test again with new posts so we don't get in the previous error of the favoriting plugin (flag -2, -1, 0, 1, 2).
I run some tests locally and it worked. Syncing the favorite flag worked correctly.
I replaced those snippets as requested and tested with fresh Ads. Unfortunately I'm still seeing error messages on favouriting and unfavouriting the Ads:
(1) Warning: A non-numeric value encountered in /.../wp-content/plugins/wp-favorite-posts/wp-favorite-posts.php on line 378
(2) Warning: Creating default object from empty value in /.../wp-content/plugins/wp-favorite-posts/wp-favorite-posts.php on line 152
I see the error is originated from the plugin "wp-favorite-posts" file. As Jamal shared the custom code I suggest you to wait for him and he will get in touch with you as soon as he back to work.
Just an update to say that Jamal will return tomorrow and be able to resume with this.
We have some unexpected absences and are currently very busy, and given the length of this thread haven't been able to take up the thread. Sorry to have kept you waiting.
Thanks for the updates. It's not a problem. We look forward to hearing from Jamal on his return. It's also easier than someone else taking up the ticket.
I was able to reproduce the issue when favoriting a new ad from a nanny by a family user. It seems that this is an edge case that the favoriting plugin does not handle. It happens for new posts because they do not have the plugin's custom field set. And the plugin does not handle this edge case (WPML duplication).
I was able to fix this issue by patching the plugin, changing the line 418 in wp-favorite-posts/wp-favorite-posts.php by changing the line from:
The function wpfp_get_post_meta does not handle the case of an empty string in its first instruction.
function wpfp_get_post_meta($post_id) {
$val = get_post_meta($post_id, WPFP_META_KEY, true); // I patched this line.
if ($val < 0) $val = 0;
return $val;
}
Please patch the file from your end and test again with new posts.
Please note, that once you update the plugin, you will lose this patch. So, I suggest you reach to the plugin's authors on GitHub and report this use case(WPML duplication) and my suggested patch hidden link
Thanks for the update, I hope you had a nice break!
When you say "patch the file" on my end - what I did was just edit that one line in the plugin and upload it again via FTP (just checking - for me it was line 413 not 418 as you suggested, perhaps this was just an oversight, or your plugin maybe had a different version?). I hope this is what you meant by "patching".
I then deactivated the plugin and reactivated it, created a new Job Ad and a new Nanny Ad and tried to favourite them. It didn't work and now I am seeing the following error on line 152:
Warning: Creating default object from empty value in /.../wp-content/plugins/wp-favorite-posts/wp-favorite-posts.php on line 152
Please let me know if I have conducted the patch correctly or advise accordingly.
Whilst you are investigating that error message, could you give please advise me of how I can filter on the favourited posts?
Obviously I need a view that filters only posts that have been favourited. I don't see any shortcode or field I can filter on. Might it be something that we need to create a shortcode for?
I was able to reproduce the same warning but I couldn't find the cause behind it, Maybe the plugin's authors can help here.
This warning is not affecting the favoriting/unfavoriting process at all. In fact, I turned debugging to hide the warning and I checked favoriting/unfavoriting for family users and the syncing is done without issues. Check this screencast hidden link
(1) I can confirm that it does seem to be working, with the debug messages off. However, I like to leave the debug display option on in DEV to track possible errors.
(2) Have you any tips as to what we ask the developer to do, or should I just report the error message to them as it stands?
(3) I need some help understanding what you wrote in the last update. I tried logging in to the "Favourites" test site we worked on together to see how it was done there, but I get the error "Error establishing a database connection". Is that site dead now? I cannot remember if we already had a "My Favourite Ads" page there or not.
Can we do a shortcode instead? Or is it advantageous or preferable to "hook into the view query filter and pass the favorites to the view's query"? My problem is I don't know how to do that! 😅😅
I see "Custom Field - wpfp-favorites" in the list of filter options, but don't know what I would set it to in order to filter the favourites correctly. Or is the method you're talking about "passed" to the view in a different way?
Can you please advise?
Thanks again for your dedicated support. It is so appreciated!
Explain also the following patch that I have implemented on your site to resolve this issue. It consists of changing line 152 from:
$post_id = &$post->ID;
To:
$post_id = isset ($post->ID) ? $post->ID : 0;
Tell them about this ticket, they will be able to view it, except for links and images.
(3) I do not think that my updates are behind these errors(database connection). Have you reverted to a backup? Because I am not encountering these errors at all.
Can we do a shortcode instead? Or is it advantageous or preferable to "hook into the view query filter and pass the favorites to the view's query"? My problem is I don't know how to do that! 😅😅
I think that hooks are more efficient. But we can still use a shortcode. I would prefer to answer this on a separate ticket 😉
I see "Custom Field - wpfp-favorites" in the list of filter options, but don't know what I would set it to in order to filter the favourites correctly. Or is the method you're talking about "passed" to the view in a different way?
I do not think that we can use this custom field inside Toolset views. The plugin stores data in this custom field in a way that will need custom code to integrate it with Toolset. I would suggest ignoring it while creating Toolset Views/Content template/archive template.
(1) and (2) Thanks for solving that other error message and enabling the display_errors again on our site. I will indeed take this issue up with the plugin developer.
(3) Regarding this, please open a separate ticket for this. I think it is clear what we need - just a way to be able to display the favourited Job Ads or Nanny Ads in a View, synced across WPML languages. If you need any logins or anything, please send me a private reply in the new tickets and I'll provide you what you need.
I think you misunderstood the first sentence of my point (3). My apologies for not expressing myself clearly. I meant here the Favourites test site we created together (hidden link)
Sorry for misunderstanding point (3). Indeed the site was crashing because of a database error. I recovered it, you can log in to check.
For some reason, I am not able to make it work with a shortcode. Even if the shortcode does return a list of IDs to pass to the view, it crashes when used inside the view's shortcode. Check this screenshot hidden link
I guess, there is no need to open a separate ticket then.
The custom code for the query filter hook and the shortcode, are both in the Toolset->Settings->Custom Code section. hidden link
Check the query filter solution on the following page and view:
- Page: hidden link
- View: hidden link
Check the query filter attempts on the following page and view:
- hidden link
- hidden link