Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save yoren/62ba549e2b819fe8750c to your computer and use it in GitHub Desktop.

Select an option

Save yoren/62ba549e2b819fe8750c to your computer and use it in GitHub Desktop.
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

yoren commented Mar 29, 2015

Copy link
Copy Markdown
Author

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