Support » Fixing WordPress » Filter Search Result by Categories !

  • I searched for hours how to do that and found only old solutions for older vcersions 🙁 I need to filter the search RESULT by categories. For example: I search for “mobile phone” and the posts with this search are in the categories “telecommunication”. So i like to list this category and when i click on it then ONLY the posts with “mobile phones” must be displayed, not all posts in this category. Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Chris Olbekson


    Level 12 Bug Squasher & Forum Moderator

    This is some code from a recent project. Your welcome to use it but please note I will not be able to offer any support on its use.

    This was used in a sidebar on the search.php template. The search.php template just needs to contain your loop.

    $taxonomies[] = array(
    	'name'      => 'category',
    	'query_var' => 'category_name',
    	'heading'   => __( 'Filter by Category' ),
    ); ?>
    <?php foreach ( $taxonomies as $tax ): ?>
    	<?php $current_term = get_query_var( $tax['query_var'] ); ?>
    <aside class="search-filter">
    <header class="head">
    	<h3><?php echo esc_html( $tax['heading'] ); ?></h3>
    <div class="content">
    <ul class="blogroll">
    	<?php if (! isset( $_GET[$tax['query_var']] ) ): ?>
    	<?php else : ?>
    	<a href="<?php echo esc_url( remove_query_arg( $tax['query_var'] ) ) ?>">All</a>
    	<?php endif; ?>
    	<?php foreach( get_terms( $tax['name'] ) as $term ): ?>
    	<?php $tax_shortcut = $tax['query_var'] ?>
    	<?php $term_shortcut = $term->slug ?>
    	<?php if ( $current_term == $term->slug ): ?>
    	<strong><?php echo esc_html( $term->name ) ?></strong>
    	<?php else : ?>
    	<a href="<?php echo esc_url( add_query_arg( $tax_shortcut, $term_shortcut ) ) ?>"><?php echo esc_html( $term->name ) ?></a>
    	<?php endif; ?>
    	<?php endforeach; ?>
    <?php endforeach ?>

    thanks i tryed it but its not exactly what im looging for. first of all, it don’t really pick the search result from specific categories, i can see it in the url it just ad the category name to the search. i would pay 100$ for the solution of my problem i spended at least 30 hours to solve it till now

    Moderator Andrew Nevins


    Forum moderator

    Try the jobs section at WordPress

    i tryed it there but my request doesn’t appear. where else can i search for programmer for wordpress?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filter Search Result by Categories !’ is closed to new replies.