“使用高级自定义字段WordPress时是否隐藏自定义字段?”

huangapple go评论68阅读模式
英文:

custom fields hidden when using Advanced custom field wordpress?

问题

Before using Advanced Custom Fields, I can show custom fields from screen options for the page.

After installing Advanced Custom Fields, custom fields hidden from screen options.

After I deactivate Advanced Custom Fields, they appear again.

Can I show custom fields after installing Advanced Custom Fields?

英文:

Before using Advanced Custom fields, I can show custom fields from screen options for the page

“使用高级自定义字段WordPress时是否隐藏自定义字段?”

After installing Advanced Custom Fields, custom fields hidden from screen options.

After I deactivate Advanced custom fields, it appear again.

can I show custom fields after installing Advanced custom fields.

答案1

得分: 1

默认情况下,高级自定义字段会移除WordPress的默认自定义字段,因为它已经为您提供了可以添加的自定义字段。但是,如果您确实需要使用默认的客户字段,那么您可以为其创建自己的元框。以下是一个示例:

function add_custom_fields_to_pages() {
  add_meta_box('custom_fields', 'Custom Fields', 'custom_fields_meta_box', 'page', 'normal', 'high');
}

function custom_fields_meta_box() {
  global $post;
  echo '<input type="hidden" name="custom_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

  echo '<div>';
  echo '<label for="custom_field">Custom Field</label>';
  echo '<input type="text" name="custom_field" value="'.get_post_meta($post->ID, 'custom_field', true).'" />';
  echo '</div>';
}

您可以更改它的名称,因为它只是一个新的元框。这里有另一个示例:https://www.smashingmagazine.com/2011/10/create-custom-post-meta-boxes-wordpress/

英文:

By Default The Advance Custom field removes the default custom field from WordPress. because it is already providing you with custom fields to be added.
But somehow if you really need to use the default customer field. then you can create your own meta boxes for that.
here is a sample example.

function add_custom_fields_to_pages() {
  add_meta_box(&#39;custom_fields&#39;, &#39;Custom Fields&#39;, &#39;custom_fields_meta_box&#39;, &#39;page&#39;, &#39;normal&#39;, &#39;high&#39;);
}

function custom_fields_meta_box() {
  global $post;
  echo &#39;&lt;input type=&quot;hidden&quot; name=&quot;custom_meta_box_nonce&quot; value=&quot;&#39;.wp_create_nonce(basename(__FILE__)).&#39;&quot; /&gt;&#39;;
 
  echo &#39;&lt;div&gt;&#39;;
  echo &#39;&lt;label for=&quot;custom_field&quot;&gt;Custom Field&lt;/label&gt;&#39;;
  echo &#39;&lt;input type=&quot;text&quot; name=&quot;custom_field&quot; value=&quot;&#39;.get_post_meta($post-&gt;ID, &#39;custom_field&#39;, true).&#39;&quot; /&gt;&#39;;
  echo &#39;&lt;/div&gt;&#39;;
}

You can change the name of it because it is only a new meta box.

here is another example: https://www.smashingmagazine.com/2011/10/create-custom-post-meta-boxes-wordpress/

huangapple
  • 本文由 发表于 2023年5月7日 15:21:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定