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]
- Custom field/meta populated by dropdown of existing posts?
- What is the index [0] for on post meta fields?
- Pass all custom fields through the same filter on post load?
- update_user_meta: How many is too many?
- Search ONLY by meta key / meta values
- Correct Approach for Validating Custom Field Input
- Query meta field using between
- Delete post based on a custom field?
- How to make custom comment fields required and message field not required
- Update meta values with AJAX
- How can I migrate all of my custom field thumbnails to the built-in post featured image?
- Multiplile values checkbox or select in custom meta box
- How to use query_posts() with a date filter on a custom field?
- Escaping Quotes
- wp_editor removes paragraph from custom meta box
- Any way to include custom fields in WP_Query results?
- How to validate custom field on lost password form before the user id field?
- Woocommerce: Custom fields and email shortcodes, ec_custom_field
- Tweak Meta for Post to work it for Pages also
- Adding an editable field to template?
- Transferring author information from a custom field to a proper author
- How to select posts from multiple categories and metavalues?
- Shortcode To Display Post Custom Field Value in Post Title, Post Content
- How to make a customized user registration form using the built in wp-register() template tag
- Link FROM attachment to full post and get custom fields values on attachment page?
- Custom field as featured image caption
- Add a custom field to my custom post type and then get posts which are before the given date in the custom field
- when looping through custom post data not appearing
- Custom Fields not working properly
- Custom meta POST request fired twice when updating a post in Gutenberg
- add meta box considers the selected option as post parent
- How do I display a custom field in an existing form on the front end?
- Extend WP_User_Query or WP_User to return all custom fields?
- Quicktag button to automatically add a custom field to a post
- Display custom fields only if it has a value
- WordPress taxonomy child image
- Create custom fields/meta data gender+country – radiobuttons and dropdown on register screen for these fields
- Add nofollow to custom field link and make domain exceptions?
- wordpress simple post multi rating with post_meta and user_meta
- Getting deleted users in database
- Custom registration form and custom field
- How can i put a custom field inside this php