The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Dynamic Default Value – Get terms by taxonomy

Labels

This Discussion is public

Notifications

This code combines wp_get_post_terms with add_shortcode to create a default value. This way you can pass data from the post with the form simply by defining the taxonomy.


/**
* Custom shortcode to get terms for the Formidable plugin
*/
function ALC_post_terms_by_taxonomy( $atts ) {
global $post;
$taxonomyTerms = wp_get_post_terms( $post->ID, $atts['taxonomy'], ‘orderby=name&hide_empty=0′ );
$term_array = array();
foreach ($taxonomyTerms as $taxonomyTerm) {
$term_array[] = $taxonomyTerm->name;
}
return implode( ‘, ‘, $term_array );
}
add_shortcode(‘get_terms_by_taxonomy’, ‘ALC_post_terms_by_taxonomy’);

And you can add them in your form by using this shortcode:
[get_terms_by_taxonomy taxonomy="taxonomy-name"]

Hi There

Really interested in this but is this code out of date now?

Running it in functions.php breaks my site.

Any help would be much appreciated!

Kind regards

Discussion closed.