[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.
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?
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?
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.
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:
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!