Title: nancyb7's Replies | WordPress.org

---

# nancyb7

  [  ](https://wordpress.org/support/users/nancyb7/)

 *   [Profile](https://wordpress.org/support/users/nancyb7/)
 *   [Topics Started](https://wordpress.org/support/users/nancyb7/topics/)
 *   [Replies Created](https://wordpress.org/support/users/nancyb7/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/nancyb7/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/nancyb7/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/nancyb7/engagements/)
 *   [Favorites](https://wordpress.org/support/users/nancyb7/favorites/)

 Search replies:

## Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGEN Gallery] Adding a Search Bar](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/#post-1189505)
 * gasjeerbij,
    Actually, you use PHP to modify the keyword string, and the code
   to put a “+” in front of each word could get rather involved. You’d have to break
   the string into words, put the “+” in front of each word, then put them back 
   into one string. But if you just want to make it a phrase search, try `$keywords
   = '"' . $keywords . '"';` near the beginning of the function, any place before
   the `$nngquery = "` line. Note: I have not tested this code.
 * In the code that I copied from Psykotik’s post, the code that you put into search.
   php removes \, +, and / from the keyword string by replacing them with blanks.
   I’m not sure of the reason for this and left it in. You could try modifying this
   line to allow the visitor more control over their search. The line is
    `$keywords
   = preg_replace('/\+/',' ',$search);` You cannot take it out completely. If you
   want to eliminate all the character changes, replace the line with this one `
   $keywords = $search;`
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGEN Gallery] Adding a Search Bar](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/#post-1189503)
 * Hi gasjeerbij,
    I think you would have to modify your keyword string to put “
   +” in front of both words. See [http://dev.mysql.com/doc/refman/4.1/en/fulltext-boolean.html](http://dev.mysql.com/doc/refman/4.1/en/fulltext-boolean.html).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGEN Gallery] Adding a Search Bar](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/#post-1189497)
 * Here is the code that goes into the search.php file:
 *     ```
       <?php
       // Start of NextGen Gallery search
       if(is_search()) {
       	$search = $wp_query->get('s');
       	$keywords = preg_replace('/\+/',' ',$search);
       	if (function_exists ('ngg_get_search_pictures')) {  // function from functions.php
       		$nggpictures = ngg_get_search_pictures($keywords, ''); // put the number of pictures by row you want, if you don't want "4"
   
       		echo "<h2>Pictures</h2>";
       		if ($nggpictures) {
       			echo $nggpictures;
       			echo '<div class="clear">&nbsp;</div>';
       		}
       		else {
       			echo '<p>No pictures were found.</p>';
       		}
       	}
       }
       // End of NextGen Gallery search
       ?>
       ```
   
 * And here is the code to add to the functions.php file:
 *     ```
       <?php
       ## Function to do search on gallery pics from NextGen Gallery plugin
       ##
       ## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)
       ##		(2) $numberPicCol (number of pic by row, if null it takes 4 )
       function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
       	global $wpdb;
       //	$count=1;
       //	if (!$numberPicRow) { $numberPicRow = "4"; }
   
       	$nngquery = "
       				SELECT pid,description,alttext
       				FROM wp_ngg_pictures
       				WHERE MATCH (description, filename, alttext) AGAINST ('$keywords' IN BOOLEAN MODE)
       				AND exclude = '0'
       ## start of tags code
       				UNION
       				SELECT pid,wp_ngg_pictures.description,alttext
       				FROM wp_ngg_pictures, wp_terms, wp_term_taxonomy, wp_term_relationships
       				WHERE wp_terms.term_id = wp_term_taxonomy.term_id and
       					wp_term_taxonomy.taxonomy = 'ngg_tag' and
       					wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and
       					wp_term_relationships.object_id = wp_ngg_pictures.pid and
       				MATCH (wp_terms.name) AGAINST ('$keywords*' IN BOOLEAN MODE)
       				AND exclude = '0'
       ## end of tags code
       				";
       	$pictures = $wpdb->get_results($nngquery, ARRAY_A);
   
       	if ($pictures) foreach($pictures as $pic) { 
   
       		$out .= '<div class="ngg-gallery-thumbnail">';
       		$out .= '<a href="'.nggGallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="thickbox" rel="singlepic'.$pic[pid].'">';
       		$out .=  '<img src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
       		$out .=  "</a></div>\n";
       // pictures use float left, so don't need the code that outputs a <br />
       //				if ($count == 0) {
       //				$out .= "<br />";
       //				}
       //				++$count;
       //				$count%=$numberPicRow;
       	}
       	return $out;
       };
       ?>
       ```
   
 * If you don’t want the description, file name, and alternate text to all be searched,
   just remove the appropriate field(s) from
    `WHERE MATCH (description, filename,
   alttext) AGAINST ('$keywords' IN BOOLEAN MODE)`
 * I commented out some code that I copied from Psykotik’s post because I didn’t
   need it, but didn’t want to lose the way the code had originally been written.
 * To search tags on posts we use this plugin [https://redmine.sproutventure.com/projects/show/search-everything](https://redmine.sproutventure.com/projects/show/search-everything).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGen Gallery] add search possibility also to pictures ! how to](https://wordpress.org/support/topic/plugin-nextgen-gallery-add-search-possibility-also-to-pictures-how-to/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-add-search-possibility-also-to-pictures-how-to/page/2/#post-868707)
 * I have posted my search code for NextGen Gallery 1.3.5 in [a more recent thread](http://wordpress.org/support/topic/304105).
   I could not have found the correct code without this thread, Psykotik’s post 
   referenced in the first post above, the newer thread [http://wordpress.org:80/support/topic/230905](http://wordpress.org:80/support/topic/230905),
   and the links it contains.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGEN Gallery] wp_ngg_tags and wp_ngg_pic2tags missing/moved after upgrade](https://wordpress.org/support/topic/plugin-nextgen-gallery-wp_ngg_tags-and-wp_ngg_pic2tags-missingmoved-after-upgrade/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-wp_ngg_tags-and-wp_ngg_pic2tags-missingmoved-after-upgrade/page/2/#post-948548)
 * I have posted my search code for NextGen Gallery 1.3.5 in [a more recent thread](http://wordpress.org/support/topic/304105),
   along with an explanation of why the search for “Elk” has problems. I could not
   have found the correct code without this thread and the links it contains, the
   older thread [http://wordpress.org:80/support/topic/206946](http://wordpress.org:80/support/topic/206946),
   and Psykotik’s post.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Plugin: NextGEN Gallery] Adding a Search Bar](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/)
 *  [nancyb7](https://wordpress.org/support/users/nancyb7/)
 * (@nancyb7)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/plugin-nextgen-gallery-adding-a-search-bar/#post-1189496)
 * I’ve been working really hard on this the last week or so, and I have code that
   works, as well as possible using a MySQL full-text search. I have relied heavily
   on the links given above, as well as others that they lead to.
 * I am using NextGen Gallery 1.3.5 and WordPress 2.8.4. My shared server provides
   PHP 4.3.11 and MySQL 4.1.14.
 * In the folder for the theme you are using, look for search.php and functions.
   php. If you don’t have a search.php, you may use the index.php or you can make
   a search.php by copying the index.php.
 * In your search.php file, insert [this code](http://realitycheck.cbftimes.com/reference/nggsearchcall.txt)
   at the place where you want the pictures to appear. In my search.php, I put it
   outside the “<?php if (have_posts()) : ?>” section because I wanted to search
   pictures whether or not there were posts found.
 * Add [this code](http://realitycheck.cbftimes.com/reference/nggsearchfunction.txt)
   to the end of functions.php. The code I found through other discussions was written
   for versions of NextGen Gallery prior to 1.0, or was poorly adapted for 1.0 and
   did not work correctly.
 * My code searches a picture’s file name, description, alternate text, and tags.
   I require an exact match for the first three because I was getting too many false
   positives using an inexact match. The tag search looks for tags that start with
   the keyword. You can easily change the exact/inexact match behavior to suit yourself:
   In the AGAINST phrase, use ‘$keywords’ to require an exact match and ‘$keywords*’
   for an inexact match. The first part of the SELECT searches file name, description,
   and alternate text, and the second part searches the tags.
 * This search method does have some peculiarities due to MySQL limitations: It 
   will not find words that have less than 4 characters or are on [this list](http://dev.mysql.com/doc/refman/4.1/en/fulltext-stopwords.html).
   If you want to use short tags or ones on the list, I suggest adding enough characters
   to the end of the tag to remove the problem, then using an inexact search to 
   find it. Remember that your visitors cannot see the actual tag on the picture.
   In one of the discussion threads, a person was having problems with the tag “
   elk”; this is why. He could get around the problem by using “elkk” or “elk_” 
   or “elk2” or any number of other variations on “elk”.
 * Since the WordPress post search does not have these problems, I assume they use
   a different search method, but I do not know MySQL or WordPress well enough to
   figure out what it might be.

Viewing 6 replies - 1 through 6 (of 6 total)