我可以告诉你如何使用WordPress功能,这非常简单,你不会丢失任何重要的东西:
上载默认值。使用WordPress媒体管理器的jpg图像。请注意图像的ID从自定义帖子类型获取所有帖子并运行set_post_thumbnail() 对于每一个示例:将此代码添加到函数中。主题或插件中的php。访问站点的管理端以使其运行。作业完成后删除它(否则每次访问管理区域时都会执行)。
add_action(\'admin_init\', function () {
    //Replace with the correct image ID
    $image_id = 45;
    $args = array(
        \'nopaging\'   => true,
        \'post_type\'  => \'listings\'
    );
    $listings = get_posts( $args );
    foreach( $listings as $listing) {
        //if has not featured image assigned, set default
        if( ! has_post_thumbnail($listing->ID) ) {
            set_post_thumbnail( $listing->ID, $image_id );
        }
    }
} );
 备选方案:不要为每个帖子设置默认图像。相反,检查帖子是否有缩略图(特色图像),如果没有显示默认值。jpg:
//Assuming we are inside the loop
if( has_post_thumbnail() ) {
    the_post_thumbnail();
} else {
    echo \'<img src="http://url.com/to/default.jpg">\';
}