I'm printing posts and I want to get number of results, how can I do that?
This is part of my code:
if (have_posts()) :
$args = array(
'showposts' => '5',
'paged' => $paged
);
$thePosts = query_posts($args);
...
Thank's for help
Simply copy the [sbs_posts] shortcode and add it to any WordPress post, page, or shortcode enabled sidebar widget. It will show the total number of published posts on your WordPress site. You can also use [sbs_blog_stats] which will show all blog stats including the total number of posts.
Place a call to query_posts() in one of your Template files before The Loop begins. The WP_Query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category).
SOLVED:
if (have_posts()) :
$args = array(
'showposts' => '5',
'paged' => $paged
);
$thePosts = query_posts($args);
global $wp_query;
echo $wp_query->found_posts;
...
To display the number of results of a search, use:
Search Result for
<?php
/* Search Count */
$allsearch = &new WP_Query("s=$s&showposts=-1");
$key = wp_specialchars($s, 1);
$count = $allsearch->post_count; _e('');
_e('<span class="search-terms">');
echo $key; _e('</span>');
_e(' — ');
echo $count . ' ';
_e('articles');
wp_reset_query();
?>
This was taken from: WP Beginner.
The correct answer is
if (have_posts()) :
$args = array(
'showposts' => '5',
'paged' => $paged
);
$thePosts = query_posts($args);
echo $thePosts ->found_posts;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With