WordPress中的Meta字段(也称为自定义字段)是一种扩展WordPress内容的方式,允许你在文章、页面或其他自定义内容类型中添加额外的信息。这些字段通常用于存储与主内容相关的元数据,如作者信息、发布日期、自定义分类等。
Dashboard
-> Plugins
。Appearance
-> Customize
,检查是否有相关设置。Settings
-> Reading
,确保没有禁用自定义字段。Settings
-> Permalinks
,确保URL设置正确。如果你使用的是自定义代码添加Meta字段,可以参考以下示例:
function add_custom_meta_box() {
add_meta_box(
'custom-meta-box',
'Custom Meta Box',
'render_custom_meta_box',
'post',
'normal',
'high'
);
}
add_action('add_meta_boxes', 'add_custom_meta_box');
function render_custom_meta_box($post) {
wp_nonce_field(basename(__FILE__), 'custom_meta_box_nonce');
$value = get_post_meta($post->ID, '_custom_meta_key', true);
echo '<label for="custom-meta-field">Custom Field</label>';
echo '<input type="text" id="custom-meta-field" name="custom_meta_field" value="' . esc_attr($value) . '" />';
}
function save_custom_meta_box($post_id) {
if (!isset($_POST['custom_meta_box_nonce']) || !wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
$value = sanitize_text_field($_POST['custom_meta_field']);
update_post_meta($post_id, '_custom_meta_key', $value);
}
add_action('save_post', 'save_custom_meta_box');
通过以上步骤和方法,你应该能够解决WordPress Meta字段未在文章编辑器中显示的问题。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云