This is the way WordPress does it:
SELECT wp_posts.* FROM wp_posts
LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = 'custom_field' )
WHERE wp_postmeta.post_id IS NULL
You can do this with WP_Query
meta_query
and 'compare' => 'NOT EXISTS'
.
Related Posts:
- SQL Query to copy value of a meta_key into another meta_key
- How to correctly call custom field dates into a posts_where filter using SQL statements
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- How to rename a custom field?
- So much data in postmeta
- What is the advantage of the wp_options design pattern?
- Remove old custom field after import
- Edit Custom Database Tables in WordPress
- importing data from non-wordpress mysql db
- How to delete custom field “suggestions” from dropdown list
- Bulk move (or copy) from a custom field to the post content?
- Up/Down voting system for WordPress
- Custom Fields Bulk Edit
- Register new user and add custom data row value for it
- After moving my site from a dev subdomain, to root, all my custom meta data is gone
- Front-end update_post_meta with ajax
- Advice needed for importing custom field data and database structure
- Leader board for game on homepage
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- Default WordPress taxonomy (Tag) – How to add a custom field to form and save it to the database
- Separate table or usermeta
- Custom User Profile Fields
- Order query by meta_value with multiple custom fields
- Custom fields not getting saved in the databse when added to the add new user profile page
- Custom Field Create Bulk via SQL Query
- Is there any way to get all meta and standard columns for any WordPress object after searching based on meta key and value
- Is there a better way to list all database terms alphabetically?
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Linking Custom Fields to Database Records
- How to populate custom field dropdown box based on prior selection?
- Meta Query And/Or
- When creating a metabox do you have to create DB fields for the data?
- Limit of char count in WP custom fields
- Adding custom field and querying from post table
- How to copy data from a custom field to the post_content?
- Diamond question mark in text after migrating content
- Get emails from users by custom field SQL
- How do I convert all custom_field php timestamps in the database to js timestamps?
- SQL: Select wordpress posts with given text string and add a custom field to them?
- Show array of meta_value in Edit Post Coloum
- Getting and calculating averge value of custom fields of the same tag
- How To Save Data From Remote APIs To ACF?
- Change word in woocommerce product category custom field
- SQL query to change the value of a Custom Field
- searching by keywords in post’s metas or pagination links problem
- Retrieving and inserting data in custom fields
- I have a form with a custom button ,i want to add the field data to an database when clicking the custom button
- update_user_meta(): invisible data storage
- Populate a select box with data stored in the database?
- Updating custom fields with external data
- Convert all dates in field to Unix time, except those already in Unix time
- query specific posts according their custom fields, using sql SELECT
- Download stuff after filling fields?
- Alter SQL query to return posts with unique custom field value, no duplicate values
- Update field name without losing the value
- Website that sells statistics
- How to create a searchable database with a single-field search box at the front end? [closed]
- difference between primary key and unique key
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- extend Meta Box / Document Panel
- Add multiple images to a page sidebar
- getEntityRecord without knowing the post type
- Add custom field to image editor
- How to break meta values into different items and avoid duplicates?
- ajax delete value from custom field array
- How can I query on the year part of a complete date in a custom field?
- WPDB: how to get the value of a field in a custom database table
- Scheduling posts in database
- WordPress Custom Field Should be Unique. Is it possible?
- How to display Meta Field Value?
- What is the cleanest way to extract custom variables from a post
- Add source URL from Feed WordPress (Syndication) plugin to a custom field in post editor
- WordPress Database Huge wp_usermeta Table
- Custom Field 101
- Insert Query not working in the form
- Is there a way to set default custom fields when creating a new post?
- Add custom column for custom field
- ul list with only as many li’s as filled custom fields
- Is there a way to dump all registered sidebar/widget?
- WordPress SQL – How to Check for Category?
- How to hide post meta
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- get_post_meta returns 0
- Custom field bug in WordPress 3.2
- Let any visitors delete a post if they know Id nr & password?
- update a custom field with the value of another existing custom field
- Ordering posts by custom fields (Date)
- PHP and Shortcode Combination
- WP Query multiple select form – meta_query help
- update_post_meta not working in action hook
- Group pages by custom field values
- How to create Parent-Child relation for custom fields?
- How to check if custom field exists in this widget query
- display loop only if a post meta data exist
- How do i output images from URL’s added to the same custom field key
- Add Custom field under the post title [closed]
- Filter Query Post by Custom Fields(by date)
- Can’t sort custom column on user.php by number / meta_value_num?
- Add CSS class to posts with certain meta key