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/