Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

If meta_key exists then don’t select this post?

There are a few ways you could do it- NOT IN, NOT EXISTS, IS NULL. Which method is best depends on your actual query.

SELECT *
FROM $wpdb->posts LEFT JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'somekey'
WHERE $wpdb->postmeta.post_id IS NULL

Related Posts:

  1. Export WordPress Posts and Meta Information in CSV format
  2. How do I find which articles are missing a featured image in The WordPress database?
  3. SQL DELETE multiple post_meta on single and multi-sites
  4. Bulk find & replace on WordPress posts/pages (minus image paths)
  5. WordPress MySQL Search and replace with wildcard?
  6. Add postmeta to all blog posts
  7. SQL query to remove first image in all posts
  8. Delete junk text from all the post using my sql command
  9. How to check if post meta key exists or not in wordpress database
  10. How to add category to: ‘wp-admin/post-new.php’?
  11. How can I retrieve multiple get_post_meta values efficiently?
  12. Code to make a post sticky
  13. MySQL Query to Retrieve Category from wp_posts
  14. How to allow hidden custom fields to be added from wp-admin/post.php?
  15. SQL Query for getting all posts in their latest revised state
  16. Delete duplicated wp_postmeta record
  17. Will a large postmeta table slow a site down?
  18. Update all posts automatically when using post_meta
  19. Search & Remove Specific Shortcode From All Posts
  20. Manually delete post from database
  21. How to batch update post content with custom post meta value
  22. how to get permalink using sql
  23. Change slug with custom field
  24. Better post meta efficiency?
  25. How to force update all posts after import
  26. Setting post meta data to random value during post status transition / on publish
  27. Edit meta data does’t work with custom sql
  28. Human Time Diff, change mins to minutes
  29. Change post format using custom field
  30. Does WP get all post_meta on POST page?
  31. Use Cron to modify posts via sql
  32. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  33. Query All users that has post
  34. Exporting Data from WordPress into a flat table
  35. Adding Multiple Values to a Post Meta Key
  36. Sql syntax error
  37. Using radio button meta data from a custom meta box
  38. get posts and postmetas in assoc array
  39. Can’t publish new posts
  40. PHP Notice error (when on 404 page)
  41. What Is meta_id In wp_postmeta?
  42. Manually removing revision post types
  43. Checking if a post with certain meta value exists
  44. How to permanently delete a post meta entry?
  45. Reset/Reorder posts ID in the MySQL wp_posts table
  46. Add custom field automatically (add_post_meta) with value based on number of words of article
  47. How to generate numbers indistinguishable for the IDs of the posts
  48. Modify WP_Post before processing
  49. Save re-arranged draggable post items to wordpress database
  50. Bulk update post slugs through database
  51. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  52. Change post_date to post_modified date on post template?
  53. Tags to Post-ID mysql query. Tag Search
  54. Get the most repeated post contents from a search?
  55. Multiples Empty Posts were created and cannot delete them
  56. WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
  57. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  58. Delete WordPress posts from URL list sql query
  59. SQL query to retrieve all the records that have not indicated category
  60. How can I sort posts by the date and a custom meta field?
  61. is there a way to show the the post title after the image?
  62. Get Meta Key Value While Saving Post
  63. wp_insert_post – duration
  64. How to verify wp user password by sql query in wp? [closed]
  65. Get ALL post ID’s export list (Only id’s. Php or sql not important )
  66. Force the “Choose from the most used tags” meta box section to always be expanded
  67. Meta value does not save for scheduled posts
  68. Custom Posts Query and meta_query Sort Order
  69. Get user categories with most posts in it
  70. MySql query to get posts with all meta and terms
  71. How to compare two posts including their meta fields on a scalable base?
  72. Getting value from get_post_custom
  73. Calling Different Custom Post Timestamps in a table
  74. Is it possible to paste a link without tags and make it directly a link in a post?
  75. Cannot retrieve a custom RSS field from posts
  76. Custom order for Mysql array
  77. List authors with the last post title and order by last post date
  78. Saving custom fields to a custom taxonomy
  79. How to Mysql select a list of posts with meta_values AND all relevant categories?
  80. Remove a shortcode from all WordPress posts
  81. Order posts alphabetically: how to set order=asc in mysql query?
  82. How to automate featured posts number? [duplicate]
  83. What do these phpMyAdmin errors mean on my WordPress databaes?
  84. What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
  85. Delete post results in “Cannot delete or update a parent row: a foreign key constraint fails”
  86. Customize rel=canonical tag for single blog post
  87. Change all author links in Blog roll
  88. How to I retrieve the ID from the Posts page?
  89. WordPress website loads more posts than expected
  90. How to save meta checkbox WordPress
  91. SQL Command for restoring trashed comments
  92. Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
  93. How to calculate the average of a post meta value(Numeric) of a specific author
  94. Is there any way to tell when wp_postmeta has been updated?
  95. update image path with words starting uppercase to lowercase chars
  96. wpColorPicker – problem with implementation to post meta
  97. Change post author without using wp_update_post()
  98. if in category but only with post meta
  99. How to Assign / Move all Deleted post to a category
  100. Migrate posts from category and sub-category via SQL
Categories posts Tags mysql, post-meta, posts, sql
How to do query_posts on tags pages
How to get price of my products show in snippet on google?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress