Check this : Get posts by meta data OR title
The first piece of code is working and allow to make a query based on meta data
You could just get rid of useless stuff (or adapt if you want to use several keys) :
$args = array(
'post_type' => 'wine'
,'meta_query' => array(
'key' => 'vintage'
,'value' => '2005'
,'compare' => '='
)
);
$query = query_posts( $args );
Related Posts:
- How to solve suspected memory issue in custom WordPress loop?
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Get_post_meta() won’t return value
- Display custom post on home page based on a metabox selection
- wp_query to find posts by year and month
- Create a random unique 6 digit number as custom field for custom post type
- How to insert content from another Custom Post type into Post?
- WP_Query orderby modified to include custom meta changes
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Meta Key Value in current-user-only loop
- Calculate all custom field values in the post loop
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- How to conditionally add Custom Post Type to Front Page
- hide specific div on single.php [closed]
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- How do you output an unknown number of images in a custom post type with desired markup?
- Get data from PHP to JavaScript to set position of each post on front page
- Get post content from another section in custom single page
- Displaying information from custom field on custom post type
- Get post-meta value of all custom-posts – lowest to highest year-count?
- Custom PT, Taxonomys and wordpress query
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- How do I list a custom field and custom taxonomies for each result in a loop?
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- when looping through custom post data not appearing
- How to avoid duplicate posts queried from custom meta?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Adding a Section for Visitors
- sorting in wp query based on custom field value
- Custom taxonomy template for custom fields loop [closed]
- Sort loop by custom field from different post type
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Error in WP Query. If variable is empty it is displaying previous post value
- WordPress loop, show only one post per custom field
- How to get past and upcoming post by defining date in custom field?
- Order by custom field attribute
- Get result from Custom Field in Custom Post type
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- loop through custom post-type with two meta_keys
- How do I filter a custom post type loop by a field?
- Add custom field to Posts and sort by it
- Orderby CPT custom fields not working
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- WP_Query order by custom field, then randomly order some of results
- A better way to add a meta box to custom post types
- Rows with custom columns not well formatted after Quick Edit save
- Plugin – Combine Meta Box Input Fields into single saveble record
- Two Custom Post Types Many to Many Relationship
- Show custom post type relationships by taxonomy
- get_post_meta not working on publishing
- Group CPT posts by custom taxonomy
- Query custom post type with ACF Date
- Custom setting to show or hide field
- Custom Meta Field – Remove comma from string with str_replace
- Best way to style first post differently?
- Using custom field content as expression in IF statement [closed]
- Meta Query Not Returning Output Despite Having Matching Values
- How to create a custom post type with additional fields?
- Callback to custom field is not working in WordPress REST API
- A to Z List of Custom Post Type in three columns
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Including metaboxes from custom post types in global search — continued
- Custom post type, organized by categories
- ACF From & To Date Validations
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- Show image gallery from a custom field
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- Dynamic dropdown select values depending on other custom field value
- How to render a custom post type template with custom fields using shortcode
- Disable saving posts as draft (make all posts mandatory regardless of the post status)
- Grouping metadatas into one
- Tracking changes in admin-page so user gets warning when leaving the page
- filter custom post in rest api with custom function
- Get Posts by multiple custom fields is not working
- Woocommerce custom field search in custom post type [closed]
- WP Query with categories only shows one post and ignores the category
- What to and how to proceed with CPT to make DB small and efficient?
- Add custom field in comments form
- Custom Fields for Custom Post [closed]
- Order Custom Post Type by Custom Field Value
- Filter custom post types by a field value
- Displaying All Posts of a Custom Post Type in WordPress Multisite Backend
- Post ID randomly printing on page
- A custom post within a custom post
- Display Custom Taxonomy Alphabetically
- Full Custom Post Type List Organised by two Taxonomies
- Repeatable Fields Metabox with Textarea (or wp_editor)
- How to use TinyMCE Editor for one of my custom post meta field?
- Displaying Custom Posts on a Page
- Custom REST endpoints for a custom post type with custom fields
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Hierarchy and access control for Custom Post Types (CPT)