WordPress Development June 30, 2024 约 4 分钟阅读

Display Post Count on WordPress Search Results Page

Author: ICai
Date: 2024-06-30
Category: WordPress Development

To display the number of articles found in the search results, you can add the following code to the appropriate location in your search.php file:

<?php
  global $wp_query;
  echo 'Found ' . $wp_query->found_posts . ' posts';
?>

Explanation:

This uses the global variable $wp_query provided by WordPress. This variable contains detailed information about the current query, and the found_posts property represents the total number of posts matching the search criteria (ignoring pagination).