I think you mean a query like this one:
$args = array(
'post_type' => 'foo',
'meta_key' => 'bar',
'meta_value' => 'pineapple',
'posts_per_page' => 1,
);
$query = new WP_Query( $args );
You can check out further information here on meta queries in WP_Query
.
If you only want to check if there exists such a post, you can use the found_posts
property:
if( $query->found_posts > 0 ){
// do stuff
}
or the usual way with the have_posts()
method:
if( $query->have_posts() ){
// do stuff
}
Related Posts:
- How to change default position of WP meta boxes?
- Custom Taxonomy as checkbox or dropdown
- Why won’t my metabox data save?
- echo value from ‘select’ field type into page template using cmb2?
- WP_List_Table Inside Metabox Not Working on Submit
- Add metabox with media uploader in a custom post type [duplicate]
- wp_generate_attachment_metadata gives me an empty array
- Best way to arrange custom post types by Attributes -> Order metabox value?
- Removing Edit Permalink/View “Custom Post Type” areas
- Unable to save custom taxonomy terms in a custom-built metabox
- How to sort CPT by custom meta value (date), and return posts month by month
- Possible to add meta box to edit.php pages?
- How can I include meta box content when searching?
- update a post meta from a single table cell TablePress
- How to create a repeatable / reusable divs in the metabox?
- How to customize the Categories meta box to allow only one category?
- wp is not defined error using wp.media to create a custom image uploader
- Displaying custom posts only if custom meta box’s date is not expired
- How can I display my custom metaboxes on a custom post template?
- Custom Post Type with metaboxes (no content) only?
- Unable to show meta box data in frontend
- advanced search forms with 3 input text and that the main problem 3 input text
- Using My-Meta-Box-Class plugin, how is ‘Date’ value stored?
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Keep display metadata value on backend – Custom Metabox
- What is the best way to correlate one-to-many content-type relationships?
- Is it possible to create relational metabox values in a custom post?
- Changing custom type name hides the posts
- Visual editor issue by having multiple tiny mce editors in a CPT
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Grouping metadatas into one
- Anon function and add_meta_box
- Show Custom Post Type meta boxes only on Page Edit
- Adding Page Templates to post but it ignored it
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- Fixed values for same post translations
- How can I move (or create another) publish button?
- Wrap meta boxes & data handling for specific post types in classes?
- Can custom fields be added without a meta box?
- Meta Box on Custom Post Type not saving
- Custom “radio button meta box” not saving correctly
- Meta Data for Custom Post Type not saving
- Remove “show sharing buttons” metabox Jetpack from custom post type
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- custom post type metaboxes not saving
- Custom post type, have only my meta boxes
- Display Repeatable Meta Box Content
- Custom Meta Box Causing Error: “Are you sure you want to do this? Please try again.”
- What do the numbers mean at the end of add_action(‘save_post’)…?
- Saving Meta Data within Custom Post Type
- A meta box (in a custom post type) with two different type of fields
- Unable to display selected post title in frontend from metabox wp_dropdown_pages()
- Values from meta-box not on $_POST
- Custom Meta Box returns no HTML
- Topic won’t save for a custom post type — how to debug?
- Get id from metabox dropdown
- Custom posttype content metabox
- Removing numerous Meta boxes from numerous CPTs
- Reusable metabox backend and frontend
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- Save Metabox Custom Field Value
- Meta box data not saving
- Meta box not appearing in my custom post type
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Adding an extra parameter [string] to my posts’ permalink?
- Empty meta-box returns publishdate if no value is set?
- Custom Post Type Meta Box Text Input Field Won’t Save When Blank
- Select Venue from dropdown list and reuse stored address information in meta_box
- Custom Meta Box with variable number of fields
- Save Custom Post Value
- Metaboxes inside Tab
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Show a custom post title in another custom post type in Meta box
- Custom Metabox Info Not Saving
- Metabox collapsed by default
- Modify Publish Metabox location on CPT
- PHP Warning with Custom Fields
- Multiple useres editing specified content
- $_POST from a Meta Box
- Custom taxonomy with custom post type archive page
- Wrong post ID in meta box callback
- Convert Custom Post Data to Javascript Array for Autocomplete
- Generating Custom Post Type list, within admin of another custom post type
- How to shows CPT which has specific meta key?
- Avoid another meta box in my custom post type
- wp_dropdown_pages doesn’t allow me to select more than one custom post type
- Delete custom post type metadata without deleting the post in admin area
- How can i embbed two different galleries in custom post type
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- Make meta box appear if the previous if not empty?
- Adapting plugin for custom post type?
- Custom post type – permalink
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- How to query custom post then display sections by meta value
- Custom meta box includes
- Post AND page parameter for WP function
- Add text to metabox input text field from Thickbox
- Display div based on Group metabox selection [closed]
- Cannot change meta box position
- Just the First Metabox what saves the data!