How can I query the wordpress database so that I’m only display the number of posts from a certain category starting at a certain date?
I’ve tried something like this but it doesn’t work:
<?php
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE term_id = '4' AND post_date >= '2014-01-01 00:00:00' " );
echo "<p>User count is {$user_count}</p>";
?>
What am I doing wrong?
Use wordpress native WP-Query:
$numberOfPosts should hold the number you are looking for. Just paste this where you used your original code which you’ve shared with us.
Read more here: https://codex.wordpress.org/Class_Reference/WP_Query
Excerpt from the above mentioned url:
You can find a bunch of other options there aswell to tweak your query, to get the desired result. This should give the result you want for now.