在将数据移动到WordPress之前,这并不是那么难,但我不确定如何得到相同的结果:一定数量的帖子属于一起(如杂志的问题)与文章,手动订购。我想从最新一期获得所有文章,并根据另一个领域订购。
用我可以做的旧桌子
select title, issue, num
from magazine
where issue = (
select max(issue)
from magazine
)
order by num
使用WordPress,数据被分成两个表,一个用于帖子(文章),另一个用于元数据。
我可以通过以下查询获取最新一期的所有文章:
select post_title, post_date from wp_posts
where ID in (select post_id
from wp_postmeta
where meta_key = 'myissue' and meta_value = (select max(meta_value + 0)
from wp_postmeta
where meta_key = 'myissue'));
问题是:如何通过其他自定义字段订购结果?
答案 0 :(得分:1)
如果您的查询没有返回很多结果,最简单的方法是使用临时表。 查询将是这样的:
SELECT * FROM (
select post_title, post_date from wp_posts
where ID in (select post_id
from wp_postmeta
where meta_key = 'myissue' and meta_value = (select max(meta_value + 0)
from wp_postmeta
where meta_key = 'myissue'))
) tmptbl ORDER BY post_date DESC;
答案 1 :(得分:1)
我找到了解决方案:
select post_title, post_date, meta_value
from wp_posts, wp_postmeta
where ID in (
select post_id
from wp_postmeta
where meta_key = 'myissue'
and meta_value = (
select max(meta_value + 0)
from wp_postmeta
where meta_key = 'myissue'
)
)
and ID = post_id
and meta_key = 'myorder'
order by meta_value + 0;