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:
- Export WordPress Posts and Meta Information in CSV format
- How do I find which articles are missing a featured image in The WordPress database?
- SQL DELETE multiple post_meta on single and multi-sites
- Bulk find & replace on WordPress posts/pages (minus image paths)
- WordPress MySQL Search and replace with wildcard?
- Add postmeta to all blog posts
- SQL query to remove first image in all posts
- Delete junk text from all the post using my sql command
- How to add category to: ‘wp-admin/post-new.php’?
- How can I retrieve multiple get_post_meta values efficiently?
- Code to make a post sticky
- MySQL Query to Retrieve Category from wp_posts
- SQL Query for getting all posts in their latest revised state
- Delete duplicated wp_postmeta record
- Will a large postmeta table slow a site down?
- Change slug with custom field
- Better post meta efficiency?
- How to force update all posts after import
- Human Time Diff, change mins to minutes
- Change post format using custom field
- Query All users that has post
- Exporting Data from WordPress into a flat table
- Adding Multiple Values to a Post Meta Key
- Sql syntax error
- Using radio button meta data from a custom meta box
- get posts and postmetas in assoc array
- Can’t publish new posts
- Checking if a post with certain meta value exists
- Add custom field automatically (add_post_meta) with value based on number of words of article
- How to generate numbers indistinguishable for the IDs of the posts
- Save re-arranged draggable post items to wordpress database
- Bulk update post slugs through database
- Change post_date to post_modified date on post template?
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- Delete WordPress posts from URL list sql query
- is there a way to show the the post title after the image?
- wp_insert_post – duration
- Custom Posts Query and meta_query Sort Order
- Calling Different Custom Post Timestamps in a table
- Cannot retrieve a custom RSS field from posts
- Saving custom fields to a custom taxonomy
- Remove a shortcode from all WordPress posts
- Delete post results in “Cannot delete or update a parent row: a foreign key constraint fails”
- Customize rel=canonical tag for single blog post
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Is there any way to tell when wp_postmeta has been updated?
- update image path with words starting uppercase to lowercase chars
- How to Assign / Move all Deleted post to a category
- Migrate posts from category and sub-category via SQL
- Display post number by category
- Updating post meta for checkbox
- Need to change all links in page content but not in post content
- Can’t update WordPress Page if post_content is Empty
- Automatic blog page with custom design [closed]
- Add multiple meta keys to a post at once
- Show number of posts by logged in user
- How does WP decide how to display a page
- How to select particular month post from table and update the post status using MySQL?
- When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
- Insert data from custom created PHP page into wp_postmeta table
- saving/reading custom field value does not work – no value gets POSTed
- Export all posts to import as product items
- get last post’s link with SQL query
- Deleting post tags removes categories
- Return records between two meta datetimes saved as strings
- WP query taxonomy optimization
- Select another post in a post meta like a parent page is selected while editing a page
- MYSQL: Create SQL query to search for string and replace
- Private post caught in endless redirect loop
- Blogposting Schema & Structured Data without plugin
- Automatically select template based on query string for New Posts
- Using a meta_value or postdate to to query and orderby
- Display Updated Date Instead of Published Date
- insert post fails after multiple postings
- Dev and prod on the same database- dev version active for IOS
- WP_Query sort by meta_value_num or date
- Grab meta data before post is saved
- How to fetch posts that are stored in the different table than the default table (wp_posts)?
- Check if user has avatar
- alt of attached image in post / pages
- Get the correct meta_value with get_post_meta
- Filter question list on substring of metavalue
- Add a meta to a post submited from a frontend form
- Export Posts with specific custom fields by sql
- Add custom class to existing menu items from custom meta
- Run function after post is updated
- Can’t create posts with WP DB Abstraction Plugin
- Adding custom fields to the Quick Edit screen – puzzled about the column concept
- FIND and REPLACE wp_posts AND IGNORE custom post type mysql query
- Special Query: Title, Terms, Content – %LIKE%
- Show related (archive) month and year to post
- SQL query : Select a thumbnail for a media
- How to create a post based on data in a table?
- How enter custom post meta or custom field on box post list archive page?
- WP_query sort by custom meta_key “price”
- What effect can a large wp_post table have on overall site performance?
- How to update wp_posts with just the returned comment count from wp_comments (SQL GROUP BY)
- How to make internal links creating plugin to respect ACF?