Show search results with Justified Image Grid?


There would be three types of search:

  • Live searching in a JIG gallery much like filtering (with JavaScript). This is not yet possible.
  • Creating galleries based on pre-defined search terms that you set up in the shortcode. This is possible with NextGEN search or Flickr search. This lets you create galleries based on a search.
  • Connecting a user's search query to JIG, instead of pre-defining it. This lets users search for things and display the results with JIG. It's considered advanced use, but can learn it from this tutorial.
The anatomy of search.php file of the theme

What complicates things is that the file, such as /wp-content/themes/Avada/search.php contains lots of extra code: for sidebars, different search layouts, displaying content (posts) so it's not possible to precisely predict what you need to modify and where. Therefore, some PHP and WordPress knowledge is needed to know what your theme's code does and where should you inject custom search code.

Furthermore, the search.php is universal, it's used for your general site search, but also for any other search type.

WordPress Media Library image search on the frontend

WordPress has no way to search the Media Library on the frontend. However there is a free plugin that helps you do just that.

  1. Install Media Search Enhanced.
  2. Add this shortcode to place the plugin's media search box (in a sidebar widget, for example). It'll point to the WordPress search page with a specialized setup.
  3. Wherever you see a search form in the code, it means to give a chance to refine search when undesirable or no results are found. Change it to the media search box, else it'll revert search to normal WP posts, confusing the visitor. For example, in Avada you'll need the following. The form is the original code, and the customization is wrapped around it:
  4. Add the actual JIG display right before the theme begins to show posts. In Avada, it's in a div with the posts-container class. The snippet attempts to use CSS to hide results that display without JIG.
  5. If results are duplicated below JIG using the style of the theme, you'll need a little extra code. Find where the loop begins with:
    Then add this immediately after that:

Please note that there is a possible limitation of this search when using WPML Media. The Media Search Enhanced plugin may show duplicates in the results due to the different language versions.

Search NextGEN Gallery or Flickr from the frontend

It's a little bit tricky, but here is how to do it:

  1. Create the ability to use the search page for something custom, it's done with a shortcode of the search box. Locate the functions.php file of your theme or the child theme, and add this:
  2. Add one of the following shortcodes to a widget or similar to place the search box. It'll initiate a specialized search in the specified source:

     [$jig_custom_search_form source=nextgen]

     [$jig_custom_search_form source=flickr]

  3.  Add the following code to your theme's search.php file, after the line where the content wrapper div starts, before any result gets shown with a loop. For your information, the JIG shortcodes will do the following:
    • NextGEN: searches for images in the NextGEN Gallery, whererever it matches any part of the filename, title, description, tags.
    • Flickr: searches for photos in a specific Flickr user and show up to 200 results (just a feasible limit).
  4. Fine tune this. The switch has 3 sources that can be searched. First, comment out the lines that you don't need. Put double slashes in front of the line like this:
  5. Generate your shortcode in the Shortcode Editor then export as a template tag. You must create yours to allow search in your profiles, but follow the examples closely. For security, do not use this to search the entire Flickr, only content in your own profile! Check out how pre-defined search works to get an idea: NextGEN search or Flickr search. This is the same thing but we are replacing the pre-defined value with an user-submitted one. Make sure the value is dynamic for any of the ng_search_query, flickr_search_text, flickr_search_tags settings:
  6. The snippet attempts to hide and prevent the theme's original search (among posts), but you should verify that nothing shows below JIG on the search results page. The custom CSS hides the area that has the post-content class, but if your theme is not Avada, this is likely different.
Helpful?  Yes  No 40% found this satisfactory.
This FAQ entry was posted in Advanced use on July 4, 2015