Hide field in backend edit screens

Support General Hide field in backend edit screensResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #46848
    DaveDave
    Participant

    Hi,
    I have a field group for frontend form and backend editing of cpt. There is one field that is specific to frontend form only. Is there a way to hide it in the backend edit screens?

    Thanks

    #46856
    PeterPeter
    Moderator

    Hello Dave,

    You can use the code to register the meta box and custom fields, then use the WordPress function is_admin() to check if the current screen isn't in the admin area and register the fields. Here is an example https://support.metabox.io/topic/rwmb_frontend_validate-and-empty-id-in-config/#post-46359

    if ( ! is_admin() ) {	
    
    	$meta_boxes[] = [
    		'title'   => 'Filter Products',
    		'post_types' => 'product',
    		'id'      => 'filter-products',
    		'context' => 'normal',
    		'fields'  => ...............
    	];
    }

    Refer to the documentation https://docs.metabox.io/creating-fields-with-code/

    #46857
    DaveDave
    Participant

    Hi,

    If I do this, the cpt in backend won't have any fields,it's just one field that I need to hide on backend. I'm not sure I understand the solution, could you please elaborate?

    Thanks

    #46863
    PeterPeter
    Moderator

    Hello Dave,

    If it is one field, you can separate the field into another field group and register it with code.

    Or use the conditional logic, create a custom callback to check the admin area and add it to the logic setting. Please follow the documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/#custom-callback

    #46864
    DaveDave
    Participant

    Thanks so much, what I'm thinking is that I'll pass through is_admin() with wp_localize_script to my js callback function. That "should" do the trick.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.