As I have stated, you need to use the current post’s ID and then return the desired meta value for the given key. This must then be passed to a meta_query
.
Just a tip, instead of using the unreliable $post
global, use the query object saved in $wp_the_query
, this will be reliable in 99.99% of the time to return the single post object on a single post page
$post = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object();
To get the meta value of then, you can do
$key = 'meta_bedroom';
$same_beds = get_post_meta(
$post->ID,
$key,
true
);
Then we need to check if we have a value, and then append our meta_query
if ( $same_beds ) {
$properties['meta_query'] = [
'key' => $key,
'value' => $same_beds
];
}
Related Posts:
- How to connect different CPTs together?
- How To Remove These Stuffs From Custom Post Type List Screen?
- Exclude a category from WP_Query
- Check if post type has term
- Setting up custom post type archives in WP3.1? Any luck?
- Query custom post type by custom field
- WordPress custom taxonomy URL rewrite on spelling errors
- Include post id[s] into WP_Query()
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- TV Show database – Best way for structuring it?
- Defining a default page for custom post type
- Using Offset in Custom Post Type Query
- How to let custom post type posts show in standard post archive (like in homepage)?
- remove post-name from title in custom post type
- Sort the main query in subcategories/terms?
- Get post info inside modal window?
- Custom Post Type single and archive pages are not working
- Add Taxonomy Values Within a Custom Post Type RSS Feed
- Paginate Custom Post Type Page
- is_singular just won’t work [closed]
- Query in a Hierarchical Custom Post Type for Children vs Siblings
- Pagination Issue: Custom Post Type In Index
- multiple search forms and search results
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Why is WordPress custom post type not showing in admin panel?
- Issue with pre_get_posts on custom post type archive pages
- Add html to cpt main page / admin edit.php
- remove permalink “front part” for custom post type
- Copy custom field value to post title
- How to show cutom post labels in options?
- Sorting Custom Post Type by Meta Value but wont display when set to 0
- Getting a PHP Notice when using Pods with WPML [closed]
- Can I list a custom post type within another custom post type in the admin area?
- Extending AZIndex plugin to use custom post types and custom taxonomies
- wordpress wp_list_pages help
- How to display custom taxonomies with links in filter menu?
- List custom taxonomy specific to one custom post type
- Rows with custom columns not well formatted after Quick Edit save
- Show child custom post types list inside single parent custom post type
- Create Connection Between two post types
- A case for Hierarchical Custom Posts
- Custom title set on quick edit
- Filter Posts from the Main Query
- WordPress Custom Search by post_type
- Custom post type Permalinks with hierarchical Taxonomies
- Enable taxonomies by post type in an array of CPTs
- Slug for custom post type
- Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’
- How does the ‘the_post_navigation()’ work for CPT’s?
- Display post from a date range from custom field
- Stores category posts in an array
- set_query_params using custom params defined in functions file?
- How to define the template for custom posts?
- Custom pages missing on “front page” setting
- Add post type pages with plugin
- Use post in multiple places on a page with multiple posts
- List all Custom Post Type posts excluding certain Taxnomy term
- Changing custom post type URL issue
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Conditional Statements
- I need help in designing a custom post type
- Get newest created custom category (get_term_by and variables) (outside Loop)
- Custom Taxonomy Taxonomies of Same Name point to first created URL
- Taxonomy terms with the same name are updated between separate custom post types
- category.php not showing custom post types
- Custom sortable column with WPAlchemy
- Custom taxonomy permalink without term, redirection to CPT slug
- Menu for taxonomies and posts belongs to taxonomy
- Display post count for a specific month
- WP_query has incorrect wp_posts.post_name = ‘asc’ when I have custom post type called ‘order’
- when looping through custom post data not appearing
- How to add badge “new” to the post title which are showed in recent post widgets in wordpress
- edit.php all post not working
- How do I create a customised table list of a custom post type (in the admin area)?
- ACF meta_key and meta_value break loop
- Parent child relation between Post and Page
- Post meta is not accessible within save_post hook
- Front-end submitted post is published with admin ID as author
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- hierarchical Custom post type child permalink not found
- Add other all taxonomies as meta boxes to custom post type
- URL with Hierarchical Taxonomies and same slug for all terms and sub-terms
- next_posts_link() always generates second page link on custom post type
- How to reset HTML filter input fields on CPT list page?
- WP Query with multiple post types ordered by custom meta date then published date
- Should I make a taxonomy to organize data like this?
- Display Custom taxonomy, Child terms and posts in a template Under Specific Parent terms
- List all posts from custom post type by taxonomy
- WordPress custom field images not getting inserted into array
- how to override menu widget?
- What would prevent a custom role from viewing posts (both standard and custom)?
- WordPress URL Problems and Layout
- Querying meta values within an array
- Show posts of parent in edit.php
- Custom Post Type Base URL
- Creating entries with image attachements within posts and managing them in a list
- How to add custom column to Custom post page list?
- Rewriting hierarchical post type
- Archive page – problem with pagination
- Load posts via AJAX without draft status