timber icon indicating copy to clipboard operation
timber copied to clipboard

found_post with Timber:get_posts();

Open paul-straetmans opened this issue 11 years ago • 1 comments

How can I get the number of post found within a get_posts query?

$args = array(
    'post_type' => 'news',
    'tag_id' => $search_tag->ID,
    'orderby' => 'rand'
);

$context['posts'] = Timber::get_posts($args);

//not working
$count_number = $args->found_posts;
$count_number = $context['posts']->found_posts;

paul-straetmans avatar Dec 21 '14 23:12 paul-straetmans

Got it working:

$posts = Timber::get_posts($args);
$context['posts'] = $posts;

$posts_number = count($posts);

paul-straetmans avatar Dec 22 '14 10:12 paul-straetmans