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]
- SQL query based on two different custom field values
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- ORA-00904: invalid identifier
- Self Join to get employee manager name
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is “Advanced” SQL?
- Why do we need “Relationships” between tables at all?
- Case statement in MySQL
- How to update multiple columns in single update statement in DB2
- How do I restore a dump file from mysqldump?
- TypeError: tuple indices must be integers, not str
- What is the difference between JOIN and UNION?
- Error Code: 2013. Lost connection to MySQL server during query
- how to drop partition without dropping data in MySQL?
- 1052: Column ‘id’ in field list is ambiguous
- 1052: Column ‘id’ in field list is ambiguous
- difference between primary key and unique key
- Creating a search form in PHP to search a database?
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- What is it exactly a BLOB in a DBMS context
- Oracle SQL query for Date format
- What is difference between SQLite and SQL
- The backend version is not supported to design database diagrams or tables
- Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?
- Postgres Error: More than one row returned by a subquery used as an expression
- How do I reset a sequence in Oracle?
- MySQL equivalent of DECODE function in Oracle
- what is the difference between triggers, assertions and checks (in database)
- How to do a batch insert in MySQL
- Solutions for INSERT OR UPDATE on SQL Server
- “select * into table” Will it work for inserting data into existing table
- Error: Duplicate entry ‘0’ for key ‘PRIMARY’
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- WP_Query – Order results by meta value
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?