gpt4 book ai didi

mysql - 从普通 SQL 查询 WordPress 数据库

转载 作者:行者123 更新时间:2023-11-29 19:56:00 25 4
gpt4 key购买 nike

免责声明:我不会使用我有特定要求的任何其他方式。

我想要的只是从帖子表加入帖子元,以便我可以获得每个帖子的特色图像。我可以通过 where 子句帖子类型为 post 并发布来获取帖子,但我不知道如何为 MySql 编写 join 来获取每个帖子的特色图像

最佳答案

你可以尝试这样的事情:

$sql = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
ORDER BY $wpdb->posts.post_date DESC
";

// Get an array of objects
$posts = $wpdb->get_results($sql, OBJECT);

您可以check more here .

关于mysql - 从普通 SQL 查询 WordPress 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40698535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com