hide a certain custom field

I am new with Wordpress,I want to hide a custom fields from particular post types and the problem is the custom fields

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
Add a comment  | 

2 Answers 2

Reset to default 1

This 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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745187521a4615707.html

相关推荐

  • hide a certain custom field

    I am new with Wordpress,I want to hide a custom fields from particular post types and the problem is the custom fields

    15小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信