WordPress如何从缩略图id获取帖子id?
我正在开发wordpress插件 我需要从WordPress如何从缩略图id获取帖子id?,wordpress,Wordpress,我正在开发wordpress插件 我需要从缩略图id中找到发布id(不反向!) 我如何才能做到这一点?您可以使用get_the_ID()获取帖子ID。您可以在wp includes/post-template.php中找到此函数 function get_the_ID() { $post = get_post(); return ! empty( $post ) ? $post->ID : false; } 您可以通过此代码获得结果 global $wpdb; $_thu
缩略图id
中找到发布id
(不反向!)
我如何才能做到这一点?您可以使用get_the_ID()获取帖子ID。您可以在wp includes/post-template.php中找到此函数
function get_the_ID() {
$post = get_post();
return ! empty( $post ) ? $post->ID : false;
}
您可以通过此代码获得结果
global $wpdb;
$_thumbnail_id = {thumbnail id};
$sql = "SELECT `post_id` FROM `wp_postmeta` WHERE `meta_value` = $_thumbnail_id";
$result = $wpdb->get_results( $sql, ARRAY_A );
//access first returned post id
var_dump($result[0]['post_id']);
如果你为多篇文章添加了相同的图片,将会有多个返回