WordPress.org

Support

Support » How-To and Troubleshooting » search results variable

search results variable

  • is there a variable that can be called to display the number of results in a search?

Viewing 6 replies - 1 through 6 (of 6 total)
  • just want to check whether anyone has any idea whether this can be done?

    ie. to show the number of results from search.

    thanks.

    I haven’t found anything yet, however I stopped looking awhile ago.

    I’m wondering the same thing. Show the number of search results, just like it shows the number of posts by a category-name. How to do this?

    Edit: realised the code posted was incorrect.

    This code (taken & modified out of a plugin) should do what you want.

    <?php
    preg_match('#FROM (.*) GROUP BY#', $request, $matches);
    $fromwhere = $matches[1];
    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    if (0 < $numposts) $numposts = number_format($numposts);
    ?>
    <?php printf(__('Your search found %1$s matching posts'), $numposts, 'edit.php'); ?>

    The complete plugin may be viewed here:

    http://www.mtaylor.co.uk/wordpress/resultscount.phps

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘search results variable’ is closed to new replies.
Skip to toolbar