Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

Custom query: Get all posts that are from a certain category?

$
0
0

This is what I have:

global $wpdb, $month;

$months = $wpdb->get_results( "SELECT *
    FROM $wpdb->posts
    WHERE post_type = 'post' AND post_status = 'publish'
    AND DATE_FORMAT( post_date_gmt, '%Y' ) = $y
    GROUP BY DATE_FORMAT( post_date_gmt, '%Y-%m' )
    ORDER BY post_date_gmt DESC
");

The problem is, this returns all posts from that time, but I want only posts that are in category 11.

Is there an easy way to achieve this?


Viewing all articles
Browse latest Browse all 44

Trending Articles