I am new with Wordpress, I want to hide a custom fields from particular post types and the problem is the custom fields are same for other post types, if I remove the custom fields it will also remove from all post types and I want to hide custom fields for only specific post types.
For example the post types are:
1.Package
2.Group tour
3.Excursion
and custom fields are
general info, price info,image,tab 1,tab2, activate itinerary tab.itineary,tab3,activate price tab,price info,include,not included..etc
from post type excursion I want to hide (included and not included).
please help me to achieve this ???
I am new with Wordpress, I want to hide a custom fields from particular post types and the problem is the custom fields are same for other post types, if I remove the custom fields it will also remove from all post types and I want to hide custom fields for only specific post types.
For example the post types are:
1.Package
2.Group tour
3.Excursion
and custom fields are
general info, price info,image,tab 1,tab2, activate itinerary tab.itineary,tab3,activate price tab,price info,include,not included..etc
from post type excursion I want to hide (included and not included).
please help me to achieve this ???
Share Improve this question edited Oct 20, 2016 at 8:34 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Oct 20, 2016 at 5:45 KuanlKuanl 113 bronze badges 1- What do you mean by hiding a custom field? From where? How do you update it then? – birgire Commented Oct 20, 2016 at 8:59
2 Answers
Reset to default 1This should do it. Tested locally and it works.
// Hide 'included' and 'not included' custom meta fields
// from the edit 'excursion' post type page.
function my_exclude_custom_fields( $protected, $meta_key ) {
if ( 'excursion' == get_post_type() ) {
if ( in_array( $meta_key, array( 'included', 'not included' ) ) ) {
return true;
}
}
return $protected;
}
add_filter( 'is_protected_meta', 'my_exclude_custom_fields', 10, 2 );
try this
add_filter('is_protected_meta', 'my_is_protected_meta_filter5', 10, 2);
function my_is_protected_meta_filter5($protected, $meta_key) {
if ( in_array( $meta_key, array( 'para1', 'para2' ) ) ) {
return true;
}
return $protected;
}