我想查询一个wordpress数据库,以便将所有期望的帖子与他们的图像并列。我设法用2个不同的查询来完成它。第一个,将所有帖子与所需的字段并列,第二个,在foreach循环中运行,以便获取每个帖子的图像。我的问题是,这需要很长的时间,我想避免身份证。我需要一个解决方案来避免第二个查询中的foreach
循环,并将它合并到第一个查询中。结合2个SQL查询以避免foreach循环
查询1
"SELECT * FROM wp_posts";
和foreach返回posts.ID
查询2
"SELECT wp_posts.guid IN (Select wp_postmeta.meta_value from wp_postmeta where wp_postmeta.meta_key = '_thumbnail_id' AND wp_postmeta.post_id = ('the returned post id foreach of ID output of the first query')"