SQL query: select duplicate posts - but using duplicate meta
how can I select the duplicate freelancer.com posts?
post_id meta_key meta_value -------- ------------------- ---------------------------------------- 1 syndication_permalink https://www.freelancer.com/projects/ 2 syndication_permalink https://www.freelancer.com/projects/ 3 syndication_permalink https://www.freelancer.com/projects/ 4 syndication_permalink https://www.simplyhired.com/job/W6sVJ1 5 syndication_permalink https://www.mandy.com/uk/job/576913/junior
I actually want to change their status to draft
*UPDATE I ended up modifying some code and somehow got this working. I have had to hack together other bits of code, my SQL sux. But it works. I just got to figure out now how to do more than 'select' but also update post status to 'draft'. can't seem to figure out how to put an UPDATE on a SELECT query now
from wp_posts as bad_rows
LEFT JOIN wp_postmeta c ON ( bad_rows.ID = c.post_id )
inner join (
select post_title,id, MIN(id) as save_this_post_id
from wp_posts
inner JOIN wp_postmeta c ON ( wp_posts.ID = c.post_id )
WHERE (
`post_status` = 'publish'
AND meta_key = 'syndication_permalink'
)
group by meta_value
having count(*) > 1
) as good_rows on good_rows.post_title = bad_rows.post_title
and good_rows.save_this_post_id <> bad_rows.id
and (bad_rows.post_status='publish' AND meta_key = 'syndication_permalink' )
order by post_title,id;
Solutions
look at http://www.mysqltutorial.org/mysql-find-duplicate-values/
to get meta values , you need to assign :
wp_postmeta.meta_key = 'syndication_permalink' AND wp_postmeta.meta_value = '$yourvalue'
Similar questions
Alter SQL query to return posts with unique custom field value, no duplicate values
I currently have a list of posts with the custom field "Name," with several posts having the same value for "Name." I would like to retrieve a list of posts that all have unique values for "Name." For example, Post 1 and Post 2 can't both be "Michael." Is there a way to do this by altering the SQL query directly, before it's executed? I am currentl...
Wordpress : Sql select posts with all related meta
I need to get an array of posts with all related meta. So it should be looks like that: What I'm trying to do: But it fails. How can I get all posts with all related meta in one query?
Exclude Duplicate Posts in this SELECT Query
I have this custom select query that pulls a specified number of posts from a specific category and displays them in the order of the latest comments. The problem is that if a post has both of the latest comments, it will get shown twice. I would like it to somehow detect duplicate posts and exclude them, showing only the most recent comment. Any i...
How to fetch all meta_key and meta_value using post_id wihout duplication of post meta using sql query
How to fetch all meta_key and meta_value using post_id wihout duplication of post meta using sql query. This query is repeting the post meta each time .
In slim-select multi-select JQuery plugin how to set our custom values or id and fetch them and compare with other select options to disable
I am using slim-select [plugin]: https://www.cssscript.com/multi-select-dropdown-component-javascript-slim-select/ in my custom form in php wordpress template. The is form option code where data comes from json file: Multi select js: Now multi select works fine but here it creates select options in div's and has random values where as I need values...
Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
I'm creating a web form on my WordPress-powered website, such that by entering a date and some upper/lower bounds into the provided fields, then submitting the form, the page will query a MySQL table, SELECT the rows which fit those criteria and dispense those values into a table on the same page. Unfortunately, I'm having a difficult time understa...