You can use get_post_field( 'post_parent' )
to get the parent ID of the current post.
Whilst ACF is technically off-topic, FWIW you can pass the ID of a post as the second parameter to get_field
.
Combined together we can fashion a shortcode centre_field
that will return any field value for the post’s parent. I’ve skipped the need for an attribute name as I think the shortcode looks a little cleaner…
e.g. [centre_field phone_number]
And the code behind it:
function wpse_405660_centre_field( $atts ) {
// Just grab the first value of the attribute array
$field_name = current( $atts );
$parent_id = get_post_field( 'post_parent' );
return get_field( $field_name, $parent_id );
}
add_shortcode( 'centre_field', 'wpse_405660_centre_field' );
Related Posts:
- Excerpt length: get first paragraph
- clients list using wordpress
- Filtering a WP_Query meta_query by numeric values isn’t working
- Automatically fill custom field value on post publish/update
- echo value from ‘select’ field type into page template using cmb2?
- Filter a custom field based on selection of another custom field (ACF) [closed]
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- 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
- Automatically assign a custom post to a custom taxonomy based on custom field value
- Saving multiple Metabox contents
- 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
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Create a post in custom post type using field in registration form after users submit form
- Copy custom field value to post title
- 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
- get_post_meta not working on publishing
- 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
- CPT archive admin menu label
- Order Custom Post Type by Custom Field Value
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cannot save CPT meta box
- 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
- Redirect to another page using contact form 7? [closed]
- Warning: Invalid argument supplied for foreach() [closed]
- How to get a custom type post data when it has a connection with another custom type post?
- ACF in wordpress
- List of users that clicked a ‘Join’ button at single post
- Custome fields not displayed
- Create short URL with auto 301 redirect
- 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
- Custom post type in Custom widget – $listItem
- 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]
- Let users upload image(s) to the post from front end
- 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
- Custom Form / Search with Custom Post Type Data
- 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
- How to convert Post Object Custom Field into Tags
- Problem with multi checkboxes value in metabox?
- filter using custom fields
- Autofill advanced custom field with user data
- Advanced search form with multiple custom fields
- WordPress page not showing up – replaced with last 10 posts?
- Custom permalink rewrite rules – how do I fix this?
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Populate custom post type/custom fields from an external database
- Fixed custom fields depending on posttype/category
- Custom Field to post_title
- 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
- Function not pulling image or text from custom post type
- 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?
- I want to split this into two functions
- How to show animal lineage/pedigree in WordPress?
- Allow authors to create article image
- ACF – Query relationship without ID
- Retrieve a post with its ACF repeater fields in wordpress
- How to I add count of custom posts listed in a post as a prefix to its title
- 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
- How to display *block number* instead *date value* on WordPress posts?
- How to select one major category (or custom taxonomy) for a custom post type?
- Specific routing for CPT
- How To Read Read Custom Post Type Data in Headless CMS Mode
- How to get lowest price from custom fields of posts