0

I am trying to run the mysql query to count the record of last one month. Here is the query:

$school_count_last_month = get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= DATE_ADD(LAST_DAY(DATE_SUB(NOW(),INTERVAL 2 MONTH)),INTERVAL 1 DAY) AND post_date <= DATE_SUB(NOW(),INTERVAL 1 MONTH)"); 

As this query working in phpmyadmin but when I tried to load my website not show anything.

Although, I have tried another sql queries in same page, but they are working perfectly.

Thanks

1 Answer 1

0

silly mistake, forgot $wpdb, it should be

$school_count_last_month = $wpdb->get_var("SELECT COUNT(*) from $wpdb->posts where post_date >= DATE_ADD(LAST_DAY(DATE_SUB(NOW(),INTERVAL 2 MONTH)),INTERVAL 1 DAY) and post_date <= DATE_SUB(NOW(),INTERVAL 1 MONTH)");
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.