Ok, I spent a lot of time trying to figure this out and hours on Google, but I just can't seem to get this to be dynamic. I have a shortcode that spits out an unordered list of taxnonomy terms associated with my Custom Post Type, but currently I have to copy & paste for each taxonomy term I want to show. I am trying to figure out how to make it dynamic in the way I can just use the same shortcode and just "pass in" a different taxonomy term.
function list_bar_location_taxonomy( $atts ) {
global $post;
$taxonomy = 'location';
$locations = get_the_terms( $post->ID, $taxonomy );
if ( ! empty( $locations ) && ! is_wp_error( $locations ) ) {
$output = '<ul class="location-meta">';
foreach( $locations as $location ) {
$output .= '<li>';
$output .= $location->name . '</li>';
}
$output .= '</ul>';
}
return $output;
}
add_shortcode( 'bars_location', 'list_bar_location_taxonomy' );
I want the taxonomy term 'location' to be interchangeable so I can pass in whatever taxonomy to be used and displayed on the front-end. e.g. taxterm2, taxterm3, etc.
I tried the following to no avail:
function list_bar_location_taxonomy( $atts ) {
$atts = shortcode_atts(
array(
'custom_taxonomy' => ' '
), $atts
);
global $post;
$locations = get_the_terms( $post->ID, $atts[ 'custom_taxonomy' ] );
if ( ! empty( $locations ) && ! is_wp_error( $locations ) ) {
$output = '<ul class="location-meta">';
foreach( $locations as $location ) {
$output .= '<li>';
$output .= $location->name . '</li>';
}
$output .= '</ul>';
}
return $output;
}
add_shortcode( 'bars_location', 'list_bar_location_taxonomy' );
Any insight as to what I am doing wrong would be greatly appreciated. Thanks.
customtype, I created a custom-taxonomy for this post-type with the slugcustomtax, I added multiple post to this type and added some terms,custom-term-1,custom-term-2,custom-term-3. I inserted the shortcode[bars_location custom_taxonomy="customtax"]into one of these custom posts. On the frontend I can now see an unordert list with the 3 terms associated with that post, e.x.Custom Term 1,Custom Term 2,Custom Term 3. What is not working for you?[bars_shortcode custom_taxonomy="customtax-location"][bars_shortcode custom_taxonomy="customtax-types-of-bars"][bars_location custom_taxonomy="customtax-someothertaxonomy"]