所以我有以下查询,但我也需要帖子精选图片,你们可以帮我查询一下吗。
SELECT SQL_CALC_FOUND_ROWS wp_posts。* FROM wp_posts,wp_term_relationships,wp_terms WHERE wp_posts.ID = wp_term_relationships.object_id和wp_posts.post_status ='发布' AND wp_terms.term_id = wp_term_relationships.term_taxonomy_id GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0,100
答案 0 :(得分:0)
我最近不得不使用精选图片检索最新的4个帖子,发现它真的很难。这段代码对我有用(最后)我知道它可能不准确,但不可能在评论中发帖,我相信它会有所帮助:
SELECT title, name, date, content, CONCAT(LEFT(image, LENGTH(image) - LOCATE('.', REVERSE(image))),'-768x576.',SUBSTRING_INDEX(image, '.', -1)) AS image
FROM (
SELECT
p.post_title AS title,
p.post_status AS 'status',
p.post_date AS date,
p.post_content AS content,
p.post_name AS name,
(SELECT `guid` FROM wp_posts WHERE id = m.meta_value) AS image
FROM wp_posts p, wp_postmeta m
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND p.id = m.post_id
AND m.meta_key = '_thumbnail_id'
LIMIT 4
) TT