Searching wishlists

ShortcodeFunction
Search[nmgr_search]nmgr_get_search_template()
Search form[nmgr_search_form]nmgr_get_search_form()
Search results[nmgr_search_results]nmgr_get_search_results()

Shortcodes and functions available for searching wishlists

The plugin search form is empowered to search wishlists in the standard wordpress areas such as title and content as well as the wishlist owner’s first name, last name, partner first name, partner last name, and email.

You can make the plugin search in extra meta fields using the filter nmgr_meta_keys_to_search.

The plugin has been designed to make searching wishlists very flexible and convenient for you. It provides a search form, a search results template, and a complete search template page for displaying and outputting the entire search functionality, which can be customized to your use with either the shortcodes or template functions above. For more details on the attributes accepted by the shortcodes and template functions see shortcodes and template functions.

It is likely you would be using shortcodes to search wishlists as most people do, so in this article I will show how the shortcodes can be used to search wishlists on your store. The template functions have however been listed here because they do exactly the same thing as the shortcodes, only directly in code.

[nmgr_search_form]

[nmgr_search_form form_action="http://example.com" input_placeholder="Search" input_required=false submit_button_text="Search"]

This shorcode simply displays the search form and can take any of the attributes above.

The input_required attribute should be set to true if you want the search form not to be posted empty. If the form_action attribute is omitted, the form is posted to the homepage by default and the search results would be displayed using the plugin’s archive template. To hide the search button you can set submit_button_text to “”.

[nmgr_search_results]

[nmgr_search_results show_results_if_no_search_query=true]

This shortcode is used to display the wishlist search results. It is only necessary to use it if you want to display the search results in a separate location to the search form. In such case, the wishlist search form should be posted to the location where this shortcode is.

By default, the shortcode shows all the wishlists on page load and when there is no search query in the url. To prevent this and show wishlist results only when there is a search query in the url, set show_results_if_no_search_query to false.

[nmgr_search show_form=true show_results=true show_results_if_no_search_query=true]

This is the main shortcode for wishlist searching and the most flexible. The other two shortcodes actually use it under the hood. With this shortcode you can display only the wishlist search form, the search results, or both. It accepts all the attributes above as well as the attributes of [nmgr_search_form], [nmgr_search] and [nmgr_archive] (See here), as the search results are displayed with the wishlist archive template.

Examples of how this shortcode works:

To show the search form only and post the search query to http://example.com/search-results:

[nmgr_search show_results=false form_action="http://example.com/search-results"]

To show the search results only:

[nmgr_search show_form=false]

To show both the search form and search results:

[nmgr_search]

To hide the search results count and page number:

[nmgr_search show_results_count=false]

To modify the search results title:

[nmgr_search title="Search results"]

Modifying the search results title

The default search results title is “Search results for %s” where %s is the search query. A more accurate way of modifying the search results title which allows you to place the search query where you want is to use the general filter for the plugin’s archive results nmgr_archive_title. In the example below, the search results title is changed to “Wishlists matching %s” where %s is the search query.

add_filter( 'nmgr_archive_title', 'my_nmgr_archive_title' );

function my_nmgr_archive_title( $title ) {
	if ( is_nmgr_search() ) {
		$search_query = get_search_query();
		$title = "Wishlists matching "$search_query"";
	}
	return $title;
}