WordPress shortcode shows as plain text in one view, works in other

I have this complex loop:

<?php

  $args = array( 
      'cat' => 54,
      'order' => 'ASC',
      'posts_per_page' => -1
  );

  $query = new WP_Query($args);   
  $q = array();

  while ( $query->have_posts() ) { 

      $query->the_post(); 

      $a = '<a href="'. get_permalink() .'"><h2>' . get_the_title() .'</h2></a>'
       . get_the_post_thumbnail() . 
      '<p>' . get_the_content("...plačiau") . '</p>';

      $categories = get_the_category();

      foreach ( $categories as $key=>$category ) {

          $b = '<h1 class="thetitle">' . $category->name . '<span>Išskleisti <i class="fa fa-arrow-circle-down"></i></span></h1>';    

      }

      $q[$b][] = $a; // Create an array with the category names and post titles
  }

  /* Restore original Post Data */
  wp_reset_postdata();

  foreach ($q as $key=>$values) {
      echo $key;

      echo '<div class="straipsniai">';
          foreach ($values as $value){
            if (count($values) == 1) {
              echo '<div class="vienas">' . $value . '</div>';
            } else if (count($values) == 2) {
              echo '<div class="du">' . $value . '</div>';
            } else if (count($values) == 3) {
              echo '<div class="trys">' . $value . '</div>';
            } else {
              echo '<div>' . $value . '</div>';
            }
          }
      echo '</div>';
  }

?>

Which worked for me, gave me this nice list/accordion:
http://bruzienesklinika.lt/web/gydytojai/

Now, each person in the category has some articles as posts and I want a list of their articles under their description. (basic Title + exerpt + read more link)

I’ve tried to do this by using “List category posts” plugin which allows me to use ” [catlist id=24] ” shortcode, but the problem is that browser prints it as plain text, source shows [catlist id=24](You can open the most bottom “GYDYTOJA REUMATOLOGĖ” tab to see that). The shortcode does work inside page, which is rendered by single.php, but it does not show when rendered in the loop I gave you in the beginning of question.

SO, the question is, how do I make the shortcode work in the initial list, where all the categories are listed with posts inside accordion.

Now it is not the problem of this certain plugin, because no shortcodes work in that accordion list.

Or maybe you have an idea how to do this the other way?


Source: shortcode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.