Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5530

vtxyzzy on "How to select posts from certain category with MySQL?"

$
0
0

I think this is what you want:

$curauth = $wp_query->get_queried_object();
$cat_id = 32;
$auth_id = $curauth->ID;
$sql = "SELECT COUNT(*)
FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
WHERE post_author = $auth_id
AND post_type = 'post'
AND post_status = 'publish'
AND post_date <= NOW()
AND tr.term_taxonomy_id = $cat_id
";
$post_count = $wpdb->get_var($sql);
echo "COUNT: $post_count<br />";

Viewing all articles
Browse latest Browse all 5530

Trending Articles