WordPress: Passing $tags to [shortcode] in sidebar for dynamic content relevant to current page

I’m using Testimonials Widget shortcode, which uses a custom post type for its content. I’m trying to put it in the sidebar displaying testimonials which share tags with the current post, and in the case of pages just display all in a rotator (testimonials_widget) rather than a list (testimonials_list). So far I can’t even get this part of it to work.

<?php 
if ($all_the_tags);
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
echo do_shortcode('[testimonialswidget_list  tags="<?php echo $this_tag->name; ?>" limit=2]');
 }
?> 

I realized after it went up that of course this wouldn’t work – it’s parsing through all the tags and showing every testimonial regardless, repeating as many times as there are tags. But at least on the posts without tags, it’s not showing anything – so I know at least some of the code is working.

Read More

Total PHP newbie here (well I’ve been working with it for years but I’m still no good at it obviously) so bear with me please, and use simple words 😉

Related posts

Leave a Reply