If in a country looking for cities
$args = array (
'post_type' => 'cities',
'meta_key' => 'country',
'meta_value' => get_the_ID()
);
This assumes that the “Country > Name* > [drop down]” you screenshot saves that the selected value using post_meta
and is saving the country’s post ID. (If it does not please adjust or specify).
UPDATE
To list cities, and retrieve their country_name, assuming the dropdown is just storing the post_title of the country, you could do:
$cities = get_posts(array (
'post_type' => 'cities',
'numberposts' => '-1',
));
foreach ($cities as $city) {
$country_name = get_post_meta($city->ID,'country_name',true);
// to get the full country, if country_name is just the post title (and not ID) you could do
# $country = get_page_by_title( $country_name, 'object', 'country' );
echo "<pre>City: {$city->post_title} is in country: {$country_name}</pre>":
}
Related Posts:
- Filtering a WP_Query meta_query by numeric values isn’t working
- Automatically fill custom field value on post publish/update
- Filter a custom field based on selection of another custom field (ACF) [closed]
- ACF Relationships in Custom Post Type Permalink
- How to sort a table of custom posts by column containing custom field
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Use Custom Post Type as Custom Field
- Display posts if a custom field value is equal to another custom field value
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Get Custom Field Values by Another Custom Field in WordPress
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Query Custom Post Types by date (custom field) range
- Custom Post type and Custom Field WP_Query
- How to change post featured image using a custom field of category?
- Retrieve value of a category’s custom field
- How can I dynamically add a post to a custom post type which uses a custom field?
- Bulk Update Custom Fields for Custom Post Types
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Order Custom Post Type by Custom Field Value
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Multiple Frontend Filters Using Advanced Custom Fields
- Integrate Custom Post Type Events into Calendar
- Displaying custom field according to date
- WebP Fallback for Inline Background Image in Style Attribute
- Query based on custom fields start and end date
- List of users that clicked a ‘Join’ button at single post
- How to inherit field value from parent post into in child / sub post
- Custome fields not displayed
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How do I replace the post title with a custom field?
- Sum and count of custom field values
- Group by custom field value (start and end times)
- Custom post types, disable fields
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Excerpt length: get first paragraph
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- ACF – Retrieve custom taxonomy from a relationship field
- Create if else for post types in WP_Query ‘post__in’ values
- Display Custom Field or Custom Taxonomy in front page /post/product
- How to access repeater field of a custom field?
- Filter posts by their related field’s custom field
- filter using custom fields
- Autofill advanced custom field with user data
- Advanced search form with multiple custom fields
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Fixed custom fields depending on posttype/category
- Automatically convert standard posts with custom fields to custom post types
- Can’t pick up a field created with Advanced Custom Fields
- Get month and day from a Date Picker custom field
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- How to show animal lineage/pedigree in WordPress?
- ACF – Query relationship without ID
- Retrieve a post with its ACF repeater fields in wordpress
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Display ACF object field data using Elementor Custom Query
- Post object GUID adding http:/
- Custom Sort Order for Custom Post Type Taxonomy
- Meta query with ACF relationship field
- Use Custom Field to Display Post Loop
- How to automatically update ACF field value every year?
- ACF – Updating all posts of CPT when a custom field from options page is updated
- Query Custom Post Type Taxonomy term with multiple parameters
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Hierarchy and access control for Custom Post Types (CPT)
- How to query WordPress posts bycustom field with a max characters’ length
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- First custom field value (out of several) displayed twice after query
- The loop seems stuck to a single (now deleted) post
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- Meta Query posts not showing on ending date of custom field
- Cannot save CPT meta box
- Cross reference custom post types
- Adding Page Templates to post but it ignored it
- Include related custom fields from one post type in another post type’s JSON feed
- How to update post meta on uploaded image from a custom form?
- How to group posts and get a mixed posts and groups view?
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- frontend image post uploader
- Is there any way to add a “custom field” to the CPT archive page?
- How to Output which matched meta_keys were found from custom_type_posts?
- Custom Post Types vs. Advanced Custom Fields (with Repeater Field add-on)
- Custom Post Fields at the beginning of a Custom Permalink
- Possible to filter custom post type with multiple meta data?
- Specific routing for CPT
- Hierarchical custom fields
- How to get a custom field value of a custom post?
- Fields for different parts of a page
- Is it possible to activate customfield ‘text description’ upon activating the customfield ‘checkbox’?
- Order post by date with ACF
- Facebook social publisher and custom post type fields [closed]
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Displaying and searching Custom Posts