开发者

Wordpress SQL statement help needed?

开发者 https://www.devze.com 2023-01-04 23:06 出处:网络
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 lit

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

精彩评论

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