Wordpress管理员:在特色图像元框中发布ID更改
我在编辑帖子时向“特色图片”元框添加选项。在metabox中,我需要访问post ID。当post.php首次加载时,这种方法可以正常工作。但是,如果我选择“选择特色图像”或“删除特色图像”,则在元数据库重新加载时,帖子ID会更改(变为静态主页ID) 以下是一些代码,将在特色图像框中显示帖子ID:Wordpress管理员:在特色图像元框中发布ID更改,wordpress,wordpress-admin,Wordpress,Wordpress Admin,我在编辑帖子时向“特色图片”元框添加选项。在metabox中,我需要访问post ID。当post.php首次加载时,这种方法可以正常工作。但是,如果我选择“选择特色图像”或“删除特色图像”,则在元数据库重新加载时,帖子ID会更改(变为静态主页ID) 以下是一些代码,将在特色图像框中显示帖子ID: add_filter( 'admin_post_thumbnail_html', 'add_options_to_featured_image' ); function add_options_to_
add_filter( 'admin_post_thumbnail_html', 'add_options_to_featured_image' );
function add_options_to_featured_image( $html ){
global $post;
$html .= '<label>Post '.$post->ID.'</label>';
return $html;
}
add_filter('admin_post_缩略图_html','add_options_至_特色图片');
函数将选项添加到图片($html){
全球$员额;
$html.='Post'.$Post->ID';
返回$html;
}
以下是重现我所见的步骤:
函数设置为接受两个参数,如下所示:
add_filter( 'admin_post_thumbnail_html', 'add_options_to_featured_image', 10, 2 );
function add_options_to_featured_image( $html, $post_id ){
$html .= '<label>Post '.$post_id.'</label>';
return $html;
}
add_filter('admin_post_缩略图_html','add_options_至_特色图片',10,2);
函数将选项添加到图片($html,$post\u id){
$html.='Post'.$Post_id';
返回$html;
}
有关更多信息,请参阅