Get Total Post Count With found_posts in WP_Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'posts_per_page' => -1, | |
'meta_query' => array( | |
array( | |
'key' => 'foo', | |
'value' => 'bar' | |
) | |
), | |
'cache_results' => false, | |
'fields' => 'ids' | |
); | |
$posts = get_posts( $f_args ); | |
$total_post_count = count( $posts ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_status' => 'publish', | |
'meta_query' => array( | |
array( | |
'key' => 'foo', | |
'value' => 'bar' | |
) | |
) | |
); | |
$posts = new WP_Query( $args ); | |
$total_post_count = $posts->found_posts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
//Main controller | |
app.controller('Main', ['$scope', '$http', function($scope, $http) { | |
$http.get('wp-json/taxonomies/category/terms').success(function(res){ | |
$scope.categories = res; | |
}); | |
$http.get('wp-json/posts/').success(function(res, status, headers){ | |
$scope.posts = res; | |
$scope.pageTitle = 'Latest Posts:'; | |
document.querySelector('title').innerHTML = 'Home | AngularJS Demo Theme'; | |
console.log(headers('X-WP-Total')); | |
}); | |
}]); | |
//... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Snippets from my post Counting Posts In WordPress.