Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress如何从缩略图id获取帖子id?_Wordpress - Fatal编程技术网

WordPress如何从缩略图id获取帖子id?

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

我正在开发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;
$_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']);
如果你为多篇文章添加了相同的图片,将会有多个返回