Skip to main contentSkip to footer

Category title in the search results page

If you’re using category restriction dropdown on your search form, here’s a bit of code that you can add to your search results template to show how many hits were found and what the category is. If no category was selected, this’ll just show how many hits were found.

<?php
    $cat = get_cat_name( $wp_query->query_vars['cat'] );
    $s = $wp_query->query_vars['s'];
    echo $wp_query->found_posts . " results found with ' $s'";
    if ( ! empty( $cat ) ) {
        echo " in the '$cat' category";
    }
?>

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Oxygen and Ninja Tables
Relevanssi has support both for Oxygen and Ninja Tables, but the way the Ninja Tables support is done, it’s not…
Issues with post order plugins
If you’re getting low-quality results and the weight settings are not affecting the results, the first thing to check is…
WPML: Category exclusions
Relevanssi category exclusion setting doesn’t work properly with WPML. Here’s a bit of code from Srdjan Jocić from OnTheGoSystems that…

Related Posts:

Comment Section:

1 Comment. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed