Inicio › Toolset Professional Support › [Resuelto] wp-admin: How to hide certain custom field inputs based on post ID
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
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)
Etiquetado: Setting up custom fields, Types plugin
Documentación relacionada:
Este tema contiene 7 respuestas, tiene 2 mensajes.
Última actualización por Minesh hace 4 años, 11 meses.
Asistido por: Minesh.
Is there a PHP function to hide certain custom fields based on the post currently being edited?
Hello. Thank you for contacting the Toolset support.
Can you please clarify where exactly you want to hide the custom fields? Do you want to hide in the backend admin while editing the post? If yes:
Please check the following Doc:
=> https://toolset.com/documentation/user-guides/custom-content/types-custom-fields-conditional-display/
if no:
Please elaborate more if that is not the case
How can I limit certain fields to only Administrators? I only see the conditional options for one field conditional upon another field.
If you want to show/hide the custom field based on the role than you need to add some custom code to your theme's functions.php file.
- You need to make sure that the custom fields you want to show/hide based on the role should be part of the custom field group. That means you should have a custom field group where you should add all those custom fields.
- Add the following code to your current theme's functions.php file:
function func_remove_specific_custom_fields() { global $post_type; global $post; global $current_user; if(!in_array('administrator',(array)$current_user->roles) and $post_type=='your-post-type'){ 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 posttype slug where you want to apply the above code.
Please feel free to adjust the above code if required and I hope the above solution will help you to resolve your issue.
More info:
=> https://codex.wordpress.org/Function_Reference/remove_meta_box
Thanks for that, but I'm wanting to remove via PHP a single Field within a Field Group.
To remove the field group, there is no such option available or needs custom CSS to remove it.
or
you should create a custom field group, move the field you wanted to that field group and use the code I shared.
Sounds like a reasonable workaround, but I'd love to see PHP be able to filter and Access to have this level of control -- maybe add an "Advanced" or "Detailed" or "Fine Grained" settings section as a feature request.
Anyway... how do I move a single Field from one Field Group to another Field Group?
Sounds like a reasonable workaround, but I'd love to see PHP be able to filter and Access to have this level of control -- maybe add an "Advanced" or "Detailed" or "Fine Grained" settings section as a feature request.
==>
Yes - Please feel free to file a feature request using the following link:
- https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Anyway... how do I move a single Field from one Field Group to another Field Group?
==>
You can create a new custom field group and add try to add the field. If you do not know how to do it, Please share admin access details and what field you want to move and I would be happy to assist.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.