在您的情况下,需要将自定义字段添加到元数据库中。过滤器的完整参考代码如下:“admin\\u post\\u thumbnail\\u html”https://developer.wordpress.org/reference/hooks/admin_post_thumbnail_html/.
让我们添加一个图像标题:
<?php
add_filter(\'admin_post_thumbnail_html\', \'custom_featured_image_field\', 10, 2);
function custom_featured_image_field($content, $post_id) {
$custom_name = ‘custom_featured_image_title’;
$custom_value = esc_attr(get_post_meta($post_id, $custom_name, true));
$output = sprintf(
‘<br><input type=“text” id="%1$s" name="%1$s" value="%2$s">\',
$custom_name, $custom_value
);
return $content .= $output;
}?>
Let’s save the newly added custom field
在这里,我们将清理用户数据并保存或更新自定义特征图像标题字段。
<?phpadd_action(\'save_post\', \'save_custom_featured_image_field\', 10, 3);
function save_custom_featured_image_field($post_ID, $post, $update) {
$custom_name = \'custom_featured_image_title\';
$custom_value = isset($_REQUEST[ $custom_name ]) ? 1 : 0;
update_post_meta($post_ID, $custom_name, $custom_value);
}?>