Skip Navigation

[Resolved] How to show search items in header of results page

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by davidm-13 3 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2027877

Hi, I have a couple of select lists (System and Action) used for input to a search I can select an item from one or both lists, the selected items are input to the search and the results are displayed on a separate page.
If I put:

  System: [wpv-post-taxonomy type="system" format="slug"]  
  Action: [wpv-post-taxonomy type="action-medicinal" format="slug"]

in the "loop items in search" section the selected search items are displayed on each result line. How can I display the selected items once in the header of the results page - inserting the above code directly after [wpv-layout-start] in the Loop editor produces blank results. Also if no selection is made from one of the lists then for that list I'd like to display "nothing selected to search".
Thanks for your help

#2028027

Hi,

Thank you for contacting us and I'd be happy to assist.

The data from the resulting posts in a view, like the post fields, taxonomy terms, etc can only be accessed, within the loop ( i.e. inside the <wpv-loop>.....</wpv-loop> tags ).

Assuming, you're referring to the view "search by complaint", I've noticed that the searched taxonomy term's slug is passed in the URL of the search results page, for example:
/complaint-search/?wpv-system=ageing&wpv-action-medicinal=anti-asthmatic

You can register a custom shortcode, which can get that term slug value from the URL and then return that term's title.

For example:


add_shortcode( 'get_term_data_custom', 'get_term_data_custom_func');
function get_term_data_custom_func($atts){
    $parameter = $atts['parameter'];
    $taxonomy = $atts['taxonomy'];
     
    if ( (!empty($parameter)) && (!empty($taxonomy)) && (!empty($_GET[$parameter])) ) {
        $category = get_term_by('slug', $_GET[$parameter], $taxonomy, 'ARRAY_A');
        if($category) {
            return $category['name'];
        }
    }
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

This shortcode accepts 2 attributes:

- parameter: the URL parameter to get the term slug from
- taxonomy: slug of the taxonomy to which the term belongs

For example to show the "system" taxonomy's searched term:


[get_term_data_custom parameter="wpv-system" taxonomy="system"]

And to show the "action-medicinal" taxonomy's searched term:


[get_term_data_custom parameter="wpv-action-medicinal" taxonomy="action-medicinal"]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2028729

Thanks very much for this, works perfect.
If possible could you tell me how to change the code so that if there's no selection for one of the lists (ie "=0") then the parameter for that list returns "not specified".
Thanks

#2028895
search-results.JPG

Hi Waqar,
Have another problem I need each result to be unique and not repeat in results list, how do I change the search to achieve this?
Thanks

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-how-to-remove-duplicated-results/

#2029267

Thanks for the update and glad that it worked.

To include the "not specified" text, you can update the code for the shortcode slightly:


add_shortcode( 'get_term_data_custom', 'get_term_data_custom_func');
function get_term_data_custom_func($atts){
    $parameter = $atts['parameter'];
    $taxonomy = $atts['taxonomy'];
      
    if ( (!empty($parameter)) && (!empty($taxonomy)) && (!empty($_GET[$parameter])) ) {
        $category = get_term_by('slug', $_GET[$parameter], $taxonomy, 'ARRAY_A');
        if($category) {
            return $category['name'];
        }
    }
    else
    {
        return 'not specified';
    }
}

You're welcome to mark this ticket as resolved and I've created a separate ticket for your question about the duplicate results.
( ref: https://toolset.com/forums/topic/split-how-to-remove-duplicated-results/ )

#2029313

My issue is resolved now. Thank you!