Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active August 29, 2015 14:17
Embed
What would you like to do?
Get Total Post Count With found_posts in WP_Query
<?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 );
<?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;
//...
//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'));
});
}]);
//...
@yoren
Copy link
Author

yoren commented Mar 29, 2015

Snippets from my post Counting Posts In WordPress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment