开发者

Wordpress SQL statement help needed?

I want to select with sql latest post from one category,I know how to select latest post from all category but dont know how to开发者_JS百科 JOIN tables.Can someone help me with this,and explain a little. My sql statement.

SELECT id,post_title,post_date FROM wp_posts ORDER BY post_date ASC

How to select from one category,I'm trying some code,looking INNER JOIN examples,but it doesnt work,help please.


Going by

Wordpress SQL statement help needed?

I'd say you want to join through to wp_terms using appropriate join conditions and specify which term you want in your WHERE clause.

SELECT
  p.*
FROM wp_posts p
JOIN wp_term_relationships wtr ON p.id = wtr.object_id
JOIN wp_term_taxonomy wtt ON wtr.term_taxonomy_id = wtt.term_taxonomy_id
JOIN wp_terms wt ON wtt.term_id = wtt.term_id
WHERE wtt.name = 'Some Term'

You may need further restrictions on the join/where.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜