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
- Using meta_query, how can i filter by a custom field and order by another one?
- Mixing regular and custom post types (with meta_query) on home page
- AJAX search on post pages by custom post type
- How to make a WP_Query search with custom post types?
- 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
- Filtering a WP_Query meta_query by numeric values isn’t working
- Display Custom Post Type Fields
- 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
- How to get the parent’s taxonomy?
- How Do I Use WP_Query to Run This Database Query as Search Result?
- 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
- query order by date on custom type: wrong order
- Used with meta_query in query_posts works slowly
- Unable to display multiple post types in same query (WPML WP_Query)
- exclude custom post type by meta key in 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
- Custom query shows custom post types in trash
- Multiple post type queries (with specific arguments for each)
- Filtering by Post Meta Custom Fields – Performance
- Is it possible to apply a meta_query to one specific post type in a query with multilple post types?
- 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
- Returning a list of custom post types excluding those without a specific meta_value
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- 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
- filter custom post type by meta key in dashboard
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Including metaboxes from custom post types in global search — continued
- Why is this query not working? (Standard posts + custom post type)
- Polylang non-default language ignores tags in WP_Query
- 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
- filter search custom field query
- 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
- How to display Related Posts based on number of taxonomy terms matched
- How to make WP_Query not to show irrelevant posts?
- Loop for custom post types filtered by a taxonomy
- WP_query – Filter by tax_query and meta_query using multiple select
- 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
- send user to first page of results when reposting to page?
- Querying meta values within an array
- Customising wordpress search and using $_GET[“s”]
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Why does ‘exclude_from_search’ exclude a custom post type from WP_Query?
- How do I correctly query posts from a post ID?
- How to exclude certain portfolios from a loop
- 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
- WP_Query() displaying past post / event
- WP Query Conditionally query meta and taxonomy
- Assign a tag to custom post type using a query
- Meta_query question
- WP_Query not using relation key as expected and not producing any results
- WP Query filtering by custom category not showing all relevant posts