• Resolved irving.bos

    (@irvingbos)


    Hi, this is an incredibly powerful plugin, thanks for it! Im feeling a little swamped in the documentation; I am looking code that will show the full gallery for a specific category (i have this part working, with pagination). Now I want to add a search box that will allow the user to search for specific images with the term in the title. When I add that code, the initial load of the page shows nothing. That is where I am stuck. How to initially load page fully (because nothing was searched for), then allow user to subset images using search box?

    As per the documentation, here is the code I am adding:
    <form id=”mla-search-form” action=”.” method=”post”>
    <input id=”mla-search-box” name=”search-string” type=”text” value=”” /> <input id=”submit” name=”submit” type=”submit” value=”Search” />
    </form>

    [mla_gallery s=”{+template:({+request:search-string+}|a-bad-term)+}” posts_per_page=12 mla_output=”paginate_links,prev_next” mla_link_href=”{+page_url+}?search-string={+request:search-string+}”]

    [mla_gallery s=”{+template:({+request:search-string+}|a-bad-term)+}” mla_nolink_text=”Enter a search value above to display gallery.” posts_per_page=12]

    thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the positive feedback, for the work you’ve done so far and for the details of your code; very helpful. I know that the documentation is more reference than tutorial and I appreciate your efforts to master it.

    I believe the solution is simple. The content template:

    {+template:({+request:search-string+}|a-bad-term)+}

    first tries to use the search-string value from the HTML request for the search argument. The | separator means “stop at the first non-empty alternative”, so if search-string is empty the template moves on to the a-bad-term literal value and uses that. Since this does not match anything, an empty gallery is composed.

    Just remove the alternative, i.e.:

    {+template:({+request:search-string+})+}

    When the search-string is empty the search argument will be empty because the () in the template means “replace missing values with an empty string”. When the search argument is empty the gallery will contain all of the items in your Media Library.

    You may have to add a post_parent=all parameter to both of your shortcodes to avoid restricting the gallery to items “attached” to the current page.

    You can find more information about Content Templates in the Documentation.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.

    Thread Starter irving.bos

    (@irvingbos)

    Thanks David, that worked great!

    irving

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

The topic ‘User-driven Search in MLA_gallery shortcode’ is closed to new replies.