You can find the post using get_posts()
and the meta query (in my example, I used meta_key
and meta_value
) like so:
See the function reference for more details on the parameters (and other examples that might help you), but the 'fields' => 'ids'
means that the function will return only the post IDs and not full post object/data.
<?php
// Find a "series" post with the meta originaltitle set to a specific value.
$ids = get_posts( array(
'post_type' => 'series',
'post_status' => 'publish',
'posts_per_page' => 1,
'meta_key' => 'originaltitle',
'meta_value' => 'put value here',
'fields' => 'ids',
) );
$post_id = array_shift( $ids );
// Or you can do something like:
/*
if ( ! empty( $ids ) ) {
$post_id = $ids[0];
// run your code
}
*/
Related Posts:
- Using Query Posts With Multiple Post Types And A Taxonomy
- Use WP_query to match post types based on custom field values
- Conditional posts in WP_query for search
- Custom Query With Multiple Meta Key Value
- Custom post type blog pagination conflict
- Fail to compare dates in meta_query
- WP_Query() show posts that end later than today
- Custom post type archive 404’s with paginate_links
- Search multiple custom fields by using meta_query
- WP_Query orderby custom field then post_date in one query
- Retrieving 3 latest post from each of 5 different custom post types
- Search Custom Post Type with all meta attached?
- filter search result with custom post type meta key
- how to group custom post type posts by custom taxonomy terms
- order by meta_value serialized array
- Can’t sort order of wp_query with 2 meta keys
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Combine tax_query and meta_query in WP_Query
- Query not returning CPT posts
- Unable to display multiple post types in same query (WPML WP_Query)
- Query for posts in 2 taxonomies
- Search tags in CPTs
- Quickest way to get last or oldest post date – WP Query
- Filter posts with meta_query NOT IN where value has multiple values
- Display custom post types with custom date field value (before today) & order by custom date field
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- CPT Meta Searching
- Multiple post type queries (with specific arguments for each)
- Sorting multiple custom post types without a meta key/value pair by sort order
- Including Custom Meta with posts_where query
- Setting proper query for multiple custom admin filters
- WP_Query: include custom post type only with specific meta value
- Display custom post type from dynamic custom field
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- wp_query check if integer exists in custom field’s array
- Get posts between custom dates
- Get latest 3 posts from multiple CPT in one query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Stuck in Order by more then one
- Including metaboxes from custom post types in global search — continued
- search suggest – filter post type
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Ways to Query Custom Post Types?
- Possible to filter custom post type with multiple meta data?
- BBPress Search results in WordPress search
- Advanced search form with filters for custom taxonomies
- How to let users choose where to search for posts?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- Loop for custom post types filtered by a taxonomy
- Custom filter for main search: how to exclude specific post_type from search results
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Getting a custom post’s custom field based on another custom post’s custom field select
- Querying multiple values from a single key
- how to get this tax_query working?
- Select2 AJAX and WP Query Returns ALL and does not filter
- WP_Query of custom post type sorted by meta_key has unexpected results
- postsperpage value not being applied
- Create a WP_Query where if the first value of the first row is equal to the second compare other value
- Best way to create a search for custom post type by custom field values
- Searching post types
- Query Posts, order by meta value
- Sorting by meta_key different to search criteria?
- Two queries – one with checkbox ticked, one without – comparing meta_query
- Custom Post Type ‘Event’: Chronological list of recurring events from meta_values in array
- Sorting the Loop by Taxonomy Value
- Custom Query: Multiple CPTs and a taxonomy filter
- WP query_posts group by meta field related
- Custom wp-query display post only today
- custom post type and a “sticky” position taxonomy
- meta query condition don’t work
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- post_type incorrect for custom post type
- Live search by custom tag
- minimize wp_query call to database
- post type => ‘any’ not applied my custom queries
- How to get the posts that my following users are liked?
- Meta_Query refuses to return results
- Query the title of the page to show posts with matching category in the loop
- Create Second Search Page Only for Custom Post Type
- Main site single-property.php design, as homepage of a multisite
- Query events post type after current date and timezone
- Imported Content Doesnt Show Up On Frontend
- Manually build WP_Query
- WP_Query with custom post type search showing all results every time
- display news with pictures 3 small and one large (loop)
- Selecting posts older than the current Unix epoch timestamp
- Filter RSS feed for custom post type to events for next 7 days only
- Query Posts From Multiple Post Types
- Trying to combine multiple WordPress queries
- send user to first page of results when reposting to page?
- Querying meta values within an array
- Why does ‘exclude_from_search’ exclude a custom post type from WP_Query?
- Searching Custom Posts content with JQuery
- Custom post archive with search, is_search() is false?
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- Order Wp Query by earliest of 3 dates meta query
- Display ACF object field data using Elementor Custom Query