Skip Navigation

[Resolved] Output a custom field value from one page, on all pages

This thread is resolved. Here is a description of the problem and solution.

Problem:
Output a custom field value from one page, on all pages

Solution:
To output custom field belongs to single post and to display it on all posts - you should use Types shortcode to display the custom field with ID attribute.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/output-a-custom-field-value-from-one-page-on-all-pages/#post-914753

Relevant Documentation:

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by andrewS-10 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#914451

Tell us what you are trying to do:

I have a custom field group, which outputs values to the home page. I would like the output (the values entered on the homepage) to appear on ALL pages of the website. Is this possible?

Thanks

#914703

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - a custom field group can be either assigned to specific or multiple post types, if you do not select any post type then it will be displayed on all post types. How you configured the custom field group settings?

#914748

Hi Minesh. Thanks for the reply.

Just to clarify:
I have a field group which will appear when editing ALL pages/posts/CPT's (by not selecting any post types, as you suggest).
This will allow me to output to every page, by entering values into the fields for that specific page.
But this is not what I want.

What I want is this:
To enter values into the fields on the homepage ONLY, and have these specific values output on ALL pages/posts/CPTs.

#914753

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Just to clarify:
I have a field group which will appear when editing ALL pages/posts/CPT's (by not selecting any post types, as you suggest).
This will allow me to output to every page, by entering values into the fields for that specific page.
But this is not what I want.
==> Ok

What I want is this:
To enter values into the fields on the homepage ONLY, and have these specific values output on ALL pages/posts/CPTs.
==> OK but there is no such feature but what we can do is what if you keep first option (a field group which will appear when editing ALL pages/posts/CPT's) - and we can restrict the field group to be available on on home page.

There is no straight forward way but I can offer you workaround that may help you.

For example - add following code to your current theme's functions.php file:

function func_remove_types_meta_box() {
    global $post_type;
    global $post;
    if($post->ID != 999){
              remove_meta_box( 'wpcf-group-YOUR-FIELD-GROUP-NAME', $post_type,'normal');
                
    }
}
add_action('admin_head', 'func_remove_types_meta_box' );

Where:
- Replace 999 with your home page ID
- Replace YOUR-FIELD-GROUP-NAME with your custom field group name slug

And then later on whenever you want to display the field value - you should use types shortcode:

For example:

[types field='field-name1' id="999"][/types]
[types field='field-name2' id="999"][/types]

Where:
- Replace 999 with your home page ID

#915080

It works! Great solution, thanks Minesh.

The simple addition of the homepage ID in the shortcode was all I needed. Your function to hide the fields (meta box) on other edit pages was a bonus. Thanks!