Long-time Toolset user here. I know Toolset allows users to display a custom field group for a given post type (or other criteria) in the editor, but I'm trying to display a custom field on just one page. Is that possible?
That URL, unfortunately, displays a 404 error message. It seems Toolset has done some housecleaning and removed older posts? If so, for those of us who use the "legacy" functionality, retaining those old posts would have been, and would still be, very helpful.
function func_remove_specific_custom_fields() {
global $post_type;
global $post;
global $current_user;
if($post_type=='your-post-type' and $post->ID==999999){
remove_meta_box( 'wpcf-group-{YOUR-POST-FIELDGROUP-SLUG}', $post_type,'normal');
}
}
add_action('admin_head', 'func_remove_specific_custom_fields' );
Where:
- Replace '{YOUR-POST-FIELDGROUP-SLUG}' with your original custom fields group slug.
- Replace 'your-post-type' with your post type slug
- Replace 999999 with post/page ID
Please feel free to adjust the above code if required and I hope the above solution will help you to resolve your issue.
Thanks for your response. It mostly makes sense, except for one thing: the code is doing the opposite of what I want it to do. It's *hiding* a custom field group for a given post type and page ID combination. I want to *display* a custom field group for a given post type and page ID combination. Should I just negate the conditionals?
Here's what I mean:
if($post_type != 'your-post-type' and $post->ID != 999999){ ... }
I tried applying this code (but modified for my needs) on my site, and it didn't work. The edit screen I'm working with is a GravityView and not the typical page or post editor (neither the block editor nor the classic editor).
After adding some debugging statements, I can see that the remove_meta_box() function is running when it's supposed to. I have verified that all of the parameters to remove_meta_box() are correct, too. I tried changing the priority of add_action(), but this did nothing. I even moved the code out of my plugin and moved it into functions.php of my theme. Nothing.