Duplicated Post Meta
-
Hello,
How the plugin decides which duplicated entries from “Duplicated Post Meta” will delete”?
-
This topic was modified 3 years, 8 months ago by
Christos Chatzaras.
-
This topic was modified 3 years, 8 months ago by
-
Hi @cybercr33p,
It deletes the meta with duplicate key and post_id. In some installs, this might happen, which is why it is set to Manual by default. Maybe I should add some information about it, somewhere (in the tutorial maybe?).
In table wp_postmeta for the same post_id there are multiple entries for meta_key (for example _stock):
post_id = 1 & _stock = 10
post_id = 1 & _stock = 9Does it remove the extra entries in this case?
Or it will only delete and keep only one if we have this:
post_id = 1 & _stock = 10
post_id = 1 & _stock = 10-
This reply was modified 3 years, 7 months ago by
Christos Chatzaras.
Currently, it only compares the post_id and the meta_key. I am afraid adding the value will make the request ultra slow and breaks.
You can try actually π By adding…
AND t1.meta_value = t2.meta_value…in the classes/queries.php file.
The count is at line 138.
The get (to look at the data) is at line 430.
The delete is a line 798.I am interested to see if it works better for you.
Jordy, aren’t postmetas supposed to have multiple rows with the same post_id and meta_key?
I ask that because the get_post_meta [https://developer.ww.wp.xz.cn/reference/functions/get_post_meta/] function has a paramether to select whether to get an array or just the first value (bool $single = false).
If you remove rows just because they have the same post_id and meta_key you are in fact destroying this capability of postmeta storing multiple values.
A solution would be to first check whether there are rows with the same post_id and meta_key and afterwards check whether the value is the same.
PS: Great job offering plugins that are not bloatware. π
Jordy, arenβt postmetas supposed to have multiple rows with the same post_id and meta_key?
Yes, they can π You are totally right. And this is why this item is set to “Manual” by default.
If you remove rows just because they have the same post_id and meta_key you are in fact destroying this capability of postmeta storing multiple values.
Exactly.
A solution would be to first check whether there are rows with the same post_id and meta_key and afterwards check whether the value is the same.
That was my struggle; I really wanted to make it work for every case, but checking the values would take too long when selecting the results.
Maybe it could be an idea to rename this item as “Potential Duplicate Post Meta”. It will show the count of all the meta entries with the meta_key and post_id, and delete only the ones with exactly the same values (but that will be checked only when deleted).
What do you think of that idea?
I think that solution would be a good one, Jordy.
As a suggestion, I would add an alert explaining to the user that it is common to have multiples entries with the same meta_key and post_id and that is the way WP intended to be and that only the ones that are clearly duplicated are being delete, in order to avoid an less experienced user thinking the plugin is not working. π
Hi @pdroms00,
I know it has been a month, but as you have probably seen, I was working on other features and enhancements.
I would like to tackle that issue gracefully now π
Could you send me a message here? https://meowapps.com/contact
I would like to prepare a new version and ask you to beta test it.Have a nice week-end!
Hi @tigroumeow,
We have had very good results from your other plugins (pro user of Media Cleaner here), and we want to install this Database Cleaner as well. But before trying this on a large production site, I decided to have a look at the support topics on here first. This one stood out to me.
“Duplicate Post Meta” is one common thing that database cleaning plugins offer to cleanup. Is there some sort of consensus on how this is done? Does your database cleaner differ in its approach to this?
See Lester Chan’s (author of WP Sweep) comment about the meaning of duplicate post meta here: https://ww.wp.xz.cn/support/topic/duplicated-post-meta-5/
We have used WP Sweep in the past, and while its a pretty decent plugin, it leaves a lot to be desired if the database is large. I am wondering now, if we may have already broken some stuff inadvertently in our WordPress installation by using the duplicate post meta cleanup feature of WP Sweep.
From @cybercr33p’s comments above, it sounds like using the duplicate post meta cleanup feature of your Database Cleaner plugin could actually break expected WordPress behavior. Please do get back us on the status of this issue to help alleviate our fears.
We will always take backups before running any database cleaning, but even so, we will greatly prefer if we don’t actually have to use the backups!
Thank you for the work you do.
Hi @rikq.
You can already use now π Keep “Duplicate Post Meta” disabled, just in case, but it is by default.
I am going to release a new version with the new behavior in 1 or 2 weeks.
-
This reply was modified 3 years, 7 months ago by
The topic ‘Duplicated Post Meta’ is closed to new replies.