Skip Navigation

[Resolved] Change the taxonomy description on ajax filter change

This support ticket is created 2 years, 6 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 6 replies, has 2 voices.

Last updated by nielsv-4 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2194615

Tell us what you are trying to do?
I have a toolset archive with a couple of taxonomy filters. The tax terms have a description and are shown when I go to the taxonomy archive but I want it to change when the user changes tax terms with the ajax filter.

Is there any documentation that you are following?
I'm trying to find similar issues on the forums but can't find any.

Is there a similar example that we can see?
hidden link
this has no text above the filter and I'm using these shortcodes in the output editor:
<h1>[wpv-taxonomy-title]</h1>
[wpv-taxonomy-description]
hidden link
On a taxonomy page it DOES show.

What is the link to your site?
hidden link

#2195545

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

To show the selected search term's title and description, you'll need a custom shortcode:


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

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 will get the selected term's slug from the URL and then show its title or description, as requested.

For example, if the taxonomy's slug is "film-category" and the URL parameter used in the search is "category", then to show the selected term's title, you can use:


[get_term_data_custom parameter="category" value="title" taxonomy="film-category"]

And similarly, to show the selected term's description, you'll use:


[get_term_data_custom parameter="category" value="description" taxonomy="film-category"]

Note: To make sure that this shortcode's value is updated every time a different term is selected in the search, you'll need to include it within the "[wpv-filter-controls]...[/wpv-filter-controls]" tags, inside the "Search and Pagination" section.

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

regards,
Waqar

#2195607

Thanks a lot, it works after a user changes category with the filter!
But I also need text in the same spot before a filter is changed. Is that possible?

Thanks again!

#2195633

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that it works.

> But I also need text in the same spot before a filter is changed. Is that possible?

- I'm not sure exactly which text and which page you're referring to.

Can you please share some more information along with the link to the page and screenshot, to make this requirement more clear?

#2195635

Thanks for the quick reply!

I have this inside the filter controls shortcode:
<h1>[get_term_data_custom parameter="category" value="title" taxonomy="film-category"]</h1>
<p>[get_term_data_custom parameter="category" value="description" taxonomy="film-category"]</p>

And it works great when a users changes the catergory with the filter, see this link:
hidden link

But I also need text in that spot on the archive page before the filter is used on this page:
hidden link

Is that possible?

#2195655

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

To show some text, when no category is selected, you can use the conditional display blocks, to check if the URL parameter "category" is set or not.
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term

For example:


[wpv-conditional if="( '[wpv-search-term param='category']' eq '' )"]

<h1>Some Heading</h1>
<p>Some description text</p>

[/wpv-conditional]

[wpv-conditional if="( '[wpv-search-term param='category']' ne '' )"]

<h1>[get_term_data_custom parameter="category" value="title" taxonomy="film-category"]</h1>
<p>[get_term_data_custom parameter="category" value="description" taxonomy="film-category"]</p>

[/wpv-conditional]

As a result, the first block's content will show, when no category is selected in search and the second one will show, when a category term is selected.

#2195689

My issue is resolved now. Thank you, you are a genius! 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.