Support » Plugin: Media Library Assistant » Help with search functionality

  • Resolved RKS213

    (@rks213)


    I have reviewed several of the posts regarding the search functionality. I have created the following:

    <form id="mla-search-form" action="." method="post" class="row">
    	<select id="mla-search-box-division" name="search-division">
    		<option value="0">Division Search</option>
    		<option value="Worldwide Group">Test Division</option>
    	</select>
    	<input id="mla-search-box-category" name="search-tag" type="text" placeholder="Category Search" />
    	<input id="submit" name="submit" type="submit" value="Search" />
    </form>
    [mla_gallery orderby=date order=desc post_mime_type=application/pdf post_parent=all s="{+template:({+request:search-tag+})+}"]
    [mla_gallery orderby=date order=desc post_mime_type=application/pdf post_parent=all s="{+template:({+request:search-tag+})+}" columns=4 mla_caption="{+title+}" size=icon link=file mla_nolink_text="Sorry. There are no results for your search. Please try your search again."]

    To explain:

    1) Disregard the select box as I have not even started trying to make this work. I’m only looking at the input at this point. The end goal is to have a search feature that can search on Att Category, Att Tag, or both together.

    2) I have created a test PDF with Att. Category = “Test Category”

    3) When I first view the page, the PDF displays as it should by default.

    4) Entering “Test Category,” “Test”, “test”, or any kind of combination returns no results. I added Att. Category = “test” as well to see if this will match but it does not. The result of any search returns the nolink message.

    https://wordpress.org/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for your question and for posting the complete source text of your form and shortcodes, which is very helpful.

    The s="{+template:({+request:search-tag+})+} parameter in your shortcodes is the “Keyword(s) Search” parameter. By default, this search will look in the Title and Description fields of your items for a match. It will not look at taxonomy terms, e.g., the Att. Categories of Att. Tags. You can add a mla_search_fields="terms" parameter to change the fields matched by the s= parameter. For more information, look in the Keyword(s) Search section of the Settings/Media Library Assistant Documentation tab.

    If searching on taxonomy terms is your primary goal, consider the more powerful “Taxonomy term keyword(s) search” parameters discussed in another Documentation section. With those parameters you can specify the taxonomies you want to search, the phrases you want to match and how multiple terms and phrases should be connected.

    You can find some additional information in this earlier topic:

    Create Gallery where Image is IN several categories (Boolean AND)

    Finally, if you haven’t already found it, here is a topic with a fairly complete search form for taxonomy terms:

    Add search box to Gallery

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the above suggestions for taxonomy term searching.

    Thread Starter RKS213

    (@rks213)

    I have two more quick questions.

    1) In all your examples, you post two shortcodes with a few differences and that is where I took the example I originally posted above. I have since removed the first one and it appears to work just fine with only one shortcode so I was wondering why there was a need for two.

    2) What is the fastest method of getting an OR in the search terms? Ie search-tag OR search-division from the above example?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for digging through all the suggestions and related topics.

    You wrote “ In all your examples, you post two shortcodes …” That’s a good question and it comes up frequently. The most important difference is the mla_output parameter, e.g., mla_output="paginate_links,prev_next". Basically, the shortcode containing this parameter generates pagination controls you can use to divide a large gallery display into smaller pages. The posts_per_page parameter controls the number of items on each page. You can find more information and examples in the “Support for Alternative Gallery Output, e.g., Pagination” section of the Documentation.

    You asked “What is the fastest method of getting an OR in the search terms?” I am not entirely sure where search-tag OR search-division appears in your example. If you are searching two or more taxonomies, they are automatically joined with OR. If you need something more complex you may have to use the hooks provided by [mla_gallery] and some PHP code to get the exact results you need. Any additional details you can provide would let me be more specific.

    Thread Starter RKS213

    (@rks213)

    What I mean in my example search-division is the select and search-tag is the input. Using either in the shortcode works perfectly. What I’m trying to get at is how to tell the shortcode, “Take the term from the select OR the term from the input.” It’s searching on the same att. terms like you mentioned above with mla_search_fields=”terms”.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for clarifying your meaning; now it makes sense.

    You can use a Content Template to get the results you want. Here is my version of your example:

    <form id="mla-search-form" action="." method="post" class="row">
    	<select id="mla-search-box-division" name="search-division">
    		<option value="">(select a value)</option>
    		<option value="abc">abc</option>
    		<option value="def">def</option>
    	</select>
    	<input id="mla-search-box-category" name="search-tag" type="text" placeholder="Category Search" />
    	<input id="submit" name="submit" type="submit" value="Search" />
    </form>
    [mla_gallery orderby=date order=desc post_mime_type=application/pdf post_parent=all mla_search_connector=OR s="{+template:({+request:search-tag+}) ({+request:search-division+})+}" mla_search_fields="terms"]

    In the form I have added <option value="">(select a value)</option>
    to have the dropdown return an empty value if nothing is selected.

    In the shortcode I have coded:

    mla_search_connector=OR s="{+template:({+request:search-tag+}) ({+request:search-division+})+}"

    The parentheses around each of the two request: parameters will eliminate them when they are missing or empty. That way you can select a division value, enter a tag value or use both. If you use both, the mla_search_connector=OR parameter will match items that match one or both of the keywords you enter.

    I hope that gives you what you need. Let me know if you have any problems or further questions regarding the above suggestions.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help with search functionality’ is closed to new replies.