You want to define a potentially huge number of different shortcodes with the same shortcode callback?
Why don’t you define a single shortcode, with a term attribute? For example
[sc term="london"]
ps:
I think your problem lies in the $tax_term->name
part, which could be a string like City of London and that’s not a valid shortcode name. Try $tax_term->slug
instead, but I don’t think it’s a good strategy!
Another problem is that you are defining a function inside the foreach loop. That should give you an error like: Fatal error: Cannot redeclare examples_shortcode() ...
.
You should consider using WP_DEBUG
in your developement. Here’s a good starting point.
Update:
You could use for example:
function square_slider_shortcode( $atts = array(), $content="" )
{
$atts = shortcode_atts( array(
'type' => 'sport', // default type
'nr' => 5, // default number of slides
), $atts, 'square_slider' );
// Sanitize input:
$type = sanitize_title( $atts['type'] );
$nr = (int) $atts['nr'];
// Output
return square_slider_template( $type, $nr );
}
add_shortcode( 'slider', 'square_slider_shortcode' );
where:
function square_slider_template( $type="", $nr = 5 )
{
// Query Arguments
$args = array(
'post_type' => 'slides',
'posts_per_page' => $nr,
'tax_query' => array(
array(
'taxonomy' => 'slides',
'field' => 'slug',
'terms' => $type,
),
),
);
// The Query
$the_query = new WP_Query( $args );
// ... etc ...
return $html;
}
Then your shortcode syntax would be:
[slider type="sport" nr="5"]
where you now can change the term (type
) and the number of slides (nr
) to your needs.