开发者

Need help with MySQL query for Wordpress

开发者 https://www.devze.com 2022-12-18 10:19 出处:网络
My problem is not with Wordpress\'s WPDB class, but with the开发者_开发技巧 MySQL syntax. I\'m trying make the following sequence work:

My problem is not with Wordpress's WPDB class, but with the开发者_开发技巧 MySQL syntax. I'm trying make the following sequence work:

  • Get an array of all Posts IDs
  • Filter out posts from a specific Category
  • Filter out duplicates, revisions, drafts etc. Only show Published content.

Help? Thank you.


Use query_posts function for that http://codex.wordpress.org/Template_Tags/query_posts by passing the category id or the category name to it. It's all explained on the link.

Edit after your comments:

You can use get_posts http://codex.wordpress.org/Template_Tags/get_posts, too, AFAIK they both return arrays.

$posts = get_posts('category=1');
foreach($posts as $post) {
    echo $post->ID; // or whatever you want to do with it...
}
0

精彩评论

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