Your question is a bit hard to read, but if I understand you on a single post page this should work:
$obj = get_queried_object();
if ('WP_Post' === get_class($obj)) {
$cellar = get_post_meta($obj->ID,'cellar_slug',true);
if (!empty($cellar)) {
$cellars = new WP_Query(
array(
'post_type' => 'post',
'numberposts' => -1,
'posts_per_page' => '1',
'meta_query' => array(
array(
'key' => 'cellar_slug',
'value' => $cellar,
)
),
'orderby' => 'menu_order',
'order' => 'ASC'
)
);
}
}
You are:
- Using
get_queried_object()
to grab the main post data - Using
get_post_meta()
to retrieve the cellar associated with the
post - And running the query only if you have a cellar
Related Posts:
- Filter widget outputs
- How to sort the admin area of a WordPress custom post type by a custom field
- Enable revisions for custom post type
- Add category base to url in custom post type/taxonomy
- Displaying Custom Post Types In “At A Glance” Meta Box
- How do I require authorization / login to view a specific set of posts / pages?
- WordPress Custom Post Types with a page as a parent?
- How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
- Custom post type URL with post ID that allows archiving and paging
- How do i display the post type title?
- Page is defaulting to archive page and not designated template
- WordPress Custom Post Type Category Page
- Custom Post Type: Set post_title equal to a custom post type field
- I can’t set meta_key in my custom post type query
- Removing parent slug from URL on custom post type
- Exclude post_type from admin comments_list
- Remove POST_TYPE from custom post type permalink
- Redirect a page based on last word in slug
- How to publish custom post type for custom role user and not “submit for review”?
- Custom post types and permalink
- Custom post types, taxonomies, and permalinks
- How to query different post types in specific order?
- WP All Import – Using Xpath to set a select value
- Displaying the first category from a custom taxonomy with get_the_terms
- How to make sure content doesn’t display if selection is empty
- Categories sorting
- Wp_query: sort by PHP variable
- How can I make my custom posts appear in their assigned category url?
- How do I create an archive page as a including metadata?
- Add tag to a custom post type doesn’t change the total of custom post type in backend
- How to create custom post by using REST API securely?
- Index page with the same id as the slug
- Update postmeta Parent when post_status child change
- How to display error message in password protected form using ajax jQuery?
- How to Create Columns with WordPress and CPTUI display page ?
- Custom post listing page layout of custom post type
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Hierarchical permalinks for custom post type and taxonomy
- WordPress make Grandparent and great grandparent filterable in custom columns
- How to organize hierarchical structure in custom post type with taxonomy (like with categories)
- Order posts by 2 custom fields and if one custom field is zero orderby another custom field
- How do I control the output of a custom post type in the loop?
- Reworking function for counting custom post type posts count
- Archieve.php not loading for custom post type
- Page listing Custom Posts
- Where is the sticky post option?
- get_posts seems to be skipping the last Post
- Dynamically insert an article at the top of a taxonomy archive – or?
- Need help deciding on a taxonomy
- post_type internal ID?
- Custom page for editing custom post type on frontend based on url
- Sum and count of custom field values
- How to show list of taxonomy terms associated with specific post?
- I have custom post type with custom taxonomy. But not found the taxonomy page..
- Custom Post Type Field Array parsing [closed]
- Fancybox loading small white square
- Add admin script to several post types
- Display latest posts of author in a custom post type
- Custom post type hierarchical loop in Homepage
- What is the most efficient way to execute recursive complex queries?
- 2 custom post type paging in 1 custom taxonomy
- My custom posts that are assigned to categories, are not called on a category search using a Category Menu
- conditional filter
- How to use pre_get_posts on archive page custom post type
- Give active class to current page on a while loop WP query for custom post types listing
- Archive per year of a custom post getting the wrong post
- Alike Shortcode using in Custom Shortcode
- Remove custom permalink base from CPT custom category and custom tags
- get taxonomies from terms
- To display the category of a specific custom post type
- Change Search display for Custom Post Type
- WooCommerce – Custom related product (Spareparts)
- Custom post type categories giving 404
- Issue with Custom Post Types and Permalinks
- Can I show some specific post rather than latest post?
- Get list of all Topics in use by a custom post type
- Connect 8 Taxonomies to One (Main) taxonomy. How to?
- Use page template instead of custom post type archive
- How do I make my archive page look like popular reviewing sites (e.g., Polygon and Gamespot) [closed]
- Cant insert wrapper div into index.php
- Custom pages for authors using a custom post type
- Trying to create an iCal file for a single post
- How to stop posts status resetting to Published
- Query Event Posts by Date
- Items By Group added to custom post type
- How to change the default orderby from “Date” to e.g. “Title” or my custom column in content type records list in admin?
- Custom Post Type – Rewrite slug [duplicate]
- How to show selected value in dropdowm menu
- Post content stays the same but permalink changes ?
- Custom Post Type Permalinks with %category%
- Pagination not working with custom loop
- How to make an admin create/edit post page to look like taxonomy page?
- Looping taxonomy in taxonomy?
- Archive Page Pagination not working
- Missing categories for Custom Taxonomy and Custom Posts
- Gravity Forms Post method [closed]
- admin search of pages returns custom post types
- Trying to set up a range filter for related custom post types
- From form submission values – dynamically update CPT “has_archive” slug and custom taxonomy “rewrite” slug value
- Two custom post type relations