Skip Navigation

[Resolved] Split: Advice regarding getting the taxonomy term title and description dynamically

This support ticket is created 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 Waqar 3 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1803109

Thanks Waqar.
Works great. I want to add filters in the results page so the original approach is not for me.

Another issue with the results page - I want every search results to have dynamic title & dynamic description below it. I want every title to be: ___ Stocks Lists

So for example, if select "renewable energy": hidden link I'll have the title: "Renewable Energy Stocks List"

I tried to add a block with field + text and chose the taxonomy "stocks category" but the output doesn't appear in the search results.

Thanks.

#1803163
wordpress category.PNG
Results 1.0.PNG

Following my last question, attached a mockup example of my specific needs for the "explore" results page:

1. Adding Breadcrumb
2. Adding title: relevant category + text ("stock list")
3. Category description

How can this be done?
Thanks

#1803221

Waqar
Supporter

Languages: English (English )

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

Thank you for sharing these details.

On the search results page, the target term's slug is available in the "wpv-stock-category" URL parameter.

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

For example:


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 active theme's "functions.php" file.

This shortcode accepts 3 attributes:

- parameter: the URL parameter to get the term slug from
- value: the required data, which can be "title" or "description"
- taxonomy: slug of the taxonomy to which the term belongs

You can get the title, using:


[get_term_data_custom parameter="wpv-stock-category" value="title" taxonomy="stock-category"]

And the description using:


[get_term_data_custom parameter="wpv-stock-category" value="description" taxonomy="stock-category"]

Combining this with with the breadcrumb and the condition to show this dynamic data, only when the term's slug exists in the URL parameter, you can include a "Fields and Text" block in your search results page and add:


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

Breadcrumb:
<a href="[wpv-bloginfo show='url']">Home</a> > [get_term_data_custom parameter="wpv-stock-category" value="title" taxonomy="stock-category"]

Title:
[get_term_data_custom parameter="wpv-stock-category" value="title" taxonomy="stock-category"] stock list

Description:
[get_term_data_custom parameter="wpv-stock-category" value="description" taxonomy="stock-category"]

[/wpv-conditional]

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#1804167

Checking, thanks.

#1804233

Waqar
Supporter

Languages: English (English )

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

{ticket status updated}

#1811003

Still working on this. Please don't close the thread yet.
Thanks

#1811163

Waqar
Supporter

Languages: English (English )

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

This ticket will stay open for the next couple of weeks.

But even if you have a follow-up question after it has been closed, you can always start a new one and include the link to this ticket for background context.

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