我的查询完美无缺:
$query = "Select * FROM prefix_posts
WHERE post_type='custompost1'
OR post_type='custompost2'
AND post_status='publish'
ORDER BY id DESC LIMIT 10";
但它只显示表中的两个字段:POST TITLE,DATE
(注意:这会在非WordPress网站上显示WordPress帖子。所以WP循环在这里不起作用。我需要一个查询。)
我需要添加第三个条目 - POST TITLE,DATE,CUSTOM FIELD
所以我需要明显改变查询。
这是我迄今为止最好的尝试:
$query = "SELECT prefix_posts.*
FROM prefix_posts, prefix_postmeta
WHERE prefix_posts.ID = prefix_postmeta.post_id
AND prefix_postmeta.meta_key = 'mymeta'
AND prefix_posts.post_status = 'publish'
AND ( prefix_posts.post_type = 'custompost1'
OR prefix_posts.post_type = 'custompost2' )
ORDER BY prefix_posts.id DESC LIMIT 10";
问题是,它没有显示“custompost2”的任何结果。
想法?
答案 0 :(得分:0)
试试这个
SELECT *
FROM wp_posts
WHERE (
post_type = 'post_type_1'
OR post_type = 'post_type_2'
)
AND post_status = 'publish'
ORDER BY id DESC