• Resolved AmyZealand

    (@amyzealand)


    Hi there,

    Just wondering how to include categories along with post titles with this great plugin. I’ve been playing with the following bit of code, but am a nubie to php and can’t quite get it….

    Any advice much appreciated 🙂

    public function ajax_response() {
    
    		// jQuery can't handle escaped URLs??
    		check_ajax_referer( $this->textdomain, 'amp;_wpnonce' );
    
    		$s = trim(stripslashes( $_GET['q'] ));
    
    		$query = new WP_Query(array(
    			's'	=>	$s
    		));
    
    		if ( ! empty($query->posts) ) {
    			foreach ( $query->posts as $post ) {
    				$results[] = $post->post_title;
    			}
    			echo join( $results, "\n" );
    		}
    
    		die;
    	}

    http://wordpress.org/extend/plugins/wp-search-suggest/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hey Amy,

    I’m not quite sure why you would want to return category names but in version 1.1 I added filters to the query args and results, so you can customize the output to your needs.

    Have a nice weekend!

    Thread Starter AmyZealand

    (@amyzealand)

    Hey Konstantin,

    Thanks very much for this great plugin! It’s really useful!

    Thanks also for your reply! Yes, I saw these options and checked tags, taxonomies & categories, but it still wasn’t searching them. It was only bringing up post & page titles. I don’t think its the theme (its twentyten) or other plugins (i tried deactivating them) but could be my php version? (5.3 on xampp)?

    Anyway, I added the bit of code below (my first go at php code ever!) and it seems to work….

    $categories = get_categories();
    		foreach ($categories as $category)
    		{
    			$results[] = $category->cat_name;
    		}
    
    		echo join( $results, "\n" );

    Thanks again and have a great weekend 🙂

    Thread Starter AmyZealand

    (@amyzealand)

    Aargh, no, my code above doesn’t work. It just brings up all the categories all the time. Hmmm, back to the drawing board….
    Will try on a different version of php.

    Thread Starter AmyZealand

    (@amyzealand)

    Hey Konstantin,

    Sorry, I’m really confused by your answer and the plugins ‘other notes’.

    Where do I update these ‘query args’? And what do I put in to include category names & tags in the suggestions?

    To answer your question, I want to include the categories so it comes up with a list of posts under that category.

    Thanks 🙂

    Hello Amy,

    I’m afraid but I think the plugin just can’t provide that. That would mean to add a hierarchy structure to the results and change the nature of the database query.
    WordPress’ built in search functionality just can’t produce that. See the plugin as a possibility to preview the titles of the posts on the search results page for the search query provided.

    I do not want to rule out that there might be a solution for that, I just don’t see how the plugin could provide that without completely refactoring the logic.

    Maybe someone else has a simple solution at hand?

    Thread Starter AmyZealand

    (@amyzealand)

    Hi Konstantin,

    Thanks so much for your reply, I really do appreciate your advice.

    I’ve spent all night trying to figure out if there is a way to ‘marry’ the ‘WP Search Suggest’ plugin with the ‘Search Everything’ plugin. Both are such great plugins, that I’ve convinced myself they should be able to work together.

    But as mentioned, I’m completely new to php and don’t quite have the skills to figure out exactly how they work.

    Do you think there is anyway I can ‘collect’ the search_terms returned by the ‘Search Everything’ plugin, and put them into the ‘WP Search Suggest’ plugin?

    Many thanks again 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Include categories in WP Search Suggest plugin’ is closed to new replies.