Last active
March 6, 2023 16:09
-
-
Save scottnunemacher/80cef7c1de9402236d6a02c359f510f2 to your computer and use it in GitHub Desktop.
Custom Search Results Subheading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom Search Results Subheading | |
add_filter( 'custom_search_results_subheading', function( $subheading ) { | |
if ( is_search() ) { | |
global $wp_query; | |
$posts_per_page = $wp_query->query_vars['posts_per_page']; | |
$posts_found = $wp_query->found_posts; | |
if ( $posts_found ) { | |
$subheading = sprintf( | |
esc_html__( 'Displaying results 1-%1$s out of %2$s for %3$s', 'total' ), | |
$posts_per_page, | |
$posts_found, | |
get_search_query( false ) | |
); | |
} | |
} | |
return $subheading; | |
} ); | |
?> | |
//Use: | |
<?php global $wp_query; echo $wp_query->found_posts.' results found.'; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment