This was a conflict with a different module which added filters to posts_where. Would there be reason or any benefit to adding remove_all_filters to posts_where, orderby, fields, etc for these very specific queries which could be run late in the loop after having several modifications?
remove_all_filters('query_vars');
remove_all_filters('posts_fields');
remove_all_filters('posts_where');
remove_all_filters('posts_join');
remove_all_filters('posts_orderby');
Also, $current_user is not globalized yet in get_nr_posts() which I imagine would always break the query.
Here’s the patch that helps resolve this for my use case and for anyone else using query modifying plugins such as Limit Post Creation.. also the $current_user global fix.
diff --git a/wp-content/plugins/limit-post-creation/limit-post-creation.php b/wp-content/plugins/limit-post-creation/limit-post-creation.php
index 017c7d7..50befa9 100644
--- a/wp-content/plugins/limit-post-creation/limit-post-creation.php
+++ b/wp-content/plugins/limit-post-creation/limit-post-creation.php
@@ -85,6 +85,11 @@ function spaw_lpc_check_cap($capabilities) {
}
$limit = intval($limit);
//retrieve number of post/page for the current user
+ remove_all_filters('query_vars');
+ remove_all_filters('posts_fields');
+ remove_all_filters('posts_where');
+ remove_all_filters('posts_join');
+ remove_all_filters('posts_orderby');
if($timeLimit=='ever'){
$posts = get_posts(array('numberposts' => $limit, 'author' => $current_user->ID, 'post_status' => 'publish','post_type'=>$page_type));
$nrPosts = count($posts);
@@ -125,6 +130,7 @@ function get_nr_post($where,$page_type) {
default:
break;
}
+global $current_user;
$query_string = array( 'author' => $current_user->ID, 'post_status' => 'publish','post_type'=>$page_type);
$query = new WP_Query( $query_string );
$NrPosts = $query->post_count;