Skip Navigation

[Resolved] Front-end form taxonomy descriptions

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to display the description field from my taxonomy next to the taxonomy input in a Form.

Solution: The wpv-taxonomy-archive shortcode can be used in a taxonomy archive, but a custom shortcode is required to display a taxonomy description outside of a taxonomy archive. Example:

// Get the description of any taxonomy, for use anywhere
// ex: [tssupp-get-tax-desc taxonomy="your-tax-slug"][/tssupp-get-tax-desc]
// https://toolset.com/forums/topic/front-end-form-taxonomy-descriptions/
add_shortcode( 'tssupp-get-tax-desc', 'tssupp_get_tax_desc');
function tssupp_get_tax_desc($atts)
{
  $atts = shortcode_atts( array(
    'taxonomy' => ''
  ), $atts );
  $taxes = get_option('wpcf-custom-taxonomies');
  $description = isset($taxes[$atts['taxonomy']]['description']) ? $taxes[$atts['taxonomy']]['description'] : '';
  return $description;
}

Use it like this:

[tssupp-get-tax-desc taxonomy="your-tax-slug"][/tssupp-get-tax-desc]

Replace your-tax-slug with the slug of the taxonomy whose description you would like to display in the Form.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-archive

This support ticket is created 3 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by MikeS1622 3 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1990391

In a similar fashion to my previous support ticket (https://toolset.com/forums/topic/front-end-form-field-descriptions/#post-1989299) I am now successfully adding descriptions to my form fields, but it doesn't work taxonomy elements in the form. Does this require custom shortcode also?

#1991067

Hello, you're talking about the description of the taxonomy itself, not an individual term in that taxonomy, correct? If so, yes, since the taxonomy description is intended for use in taxonomy archives, displaying that text elsewhere would also require a custom shortcode. Normally in a taxonomy archive you could display the description with the wpv-taxonomy-archive shortcode, but that doesn't work in the context of a Form. Here is a custom shortcode you can use:

// Get the description of any taxonomy, for use anywhere
// ex: [tssupp-get-tax-desc taxonomy="your-tax-slug"][/tssupp-get-tax-desc]
// https://toolset.com/forums/topic/front-end-form-taxonomy-descriptions/
add_shortcode( 'tssupp-get-tax-desc', 'tssupp_get_tax_desc');
function tssupp_get_tax_desc($atts)
{
  $atts = shortcode_atts( array(
    'taxonomy' => ''
  ), $atts );
  $taxes = get_option('wpcf-custom-taxonomies');
  $description = isset($taxes[$atts['taxonomy']]['description']) ? $taxes[$atts['taxonomy']]['description'] : '';
  return $description;
}

Use it like this:

[tssupp-get-tax-desc taxonomy="your-tax-slug"][/tssupp-get-tax-desc]

Replace your-tax-slug with the slug of the taxonomy whose description you would like to display.

#1991077

This amazing, thanks. Just to check, do I need the second part of the shortcode, i.e.

[/tssupp-get-tax-desc]

? In the solution to my previous thread the shortcode didn't have this sort of closing tag part. And if it works either way, what does using the closing tag allow me to do?

#1991181

That's a good question. Either way might be acceptable depending how the shortcode is coded. In the case of these two shortcodes, closing tags are not explicitly required, but in other shortcodes they might be. I try to use closing shortcode tags either way as a general practice to help prevent confusion about whether or not the shortcode should enclose content with a closing tag. Someone without knowledge of the shortcode might be debugging an issue, look at the content and think "This shortcode is missing a closing tag, that might be the problem," when in fact it's unrelated. More technical information about this: https://developer.wordpress.org/plugins/shortcodes/enclosing-shortcodes/

#1991319

My issue is resolved now. Thank you!