Created
December 1, 2023 03:59
-
-
Save getneerajk/82b897e80afbba67d8a16a7b195b9029 to your computer and use it in GitHub Desktop.
Search result count #wp #search
This file contains hidden or 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 | |
$query_cpt = new WP_Query($args); | |
$posts_per_page = $query_cpt->query_vars['posts_per_page']; | |
$posts_found = $query_cpt->found_posts; | |
$paged = $query_cpt->query_vars['paged']; | |
if ( $posts_found ) { | |
$start_result = ( $paged - 1 ) * $posts_per_page + 1; | |
$end_result = min( $paged * $posts_per_page, $posts_found ); | |
echo '<div class="sc-search-result-stat">'; | |
echo 'Showing <span>' . $start_result . '-' . $end_result . '</span> out of <span>' . $posts_found . '</span> for <span>"' . esc_html( $_GET['s'] ).'"</span>'; | |
echo '</div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment