Title: dynamic variable issues in theme
Last modified: August 21, 2016

---

# dynamic variable issues in theme

 *  [everything_is_fine](https://wordpress.org/support/users/chiseledimages/)
 * (@chiseledimages)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/dynamic-variable-issues-in-theme/)
 * I’m using this on a post archive template for a custom post-type called services.
 * I first tried
 *     ```
       while ( have_posts() ) : the_post();
                 $id= get_the_ID();
       do_shortcode('[post-content show_image=true show_title=true post_type="services" id='.$id.' shortcodes=true image_width=300 image_height=300]');
        endwhile;
       ```
   
 * That didn’t work at all. Even though I could echo the ID fine to the page it 
   would not get the post-content for the pages. If I hardcoded a post-id in place
   of the variable it would work and display the same content over and over.
 * So then I tried adding the page ids’ to an array and then cycling through the
   array (just trial and error till I found something that worked).
 * So now I have
 *     ```
       <?php
                               $servarray = array();
   
                                while ( have_posts() ) : the_post();
                                  $id= get_the_ID();
                                  $servarray[].= $id;
   
                                    endwhile;                                     ?>
       <div id="serv-full-conent">
   
                               </div>
   
                       <?php             foreach ($servarray as $value) {
                               echo '<div id="serv-load-post-'.$value.'" style="width: 20%; margin-left: 33%;" class="serv-hide"> ';
                                            $serv_article = '[post-content show_image=true show_title=true post_type="services" id='.$value.' shortcodes=true image_width=300 image_height=300]';
                                              echo do_shortcode($serv_article);
   
                                  echo '</div>';
                       } ?>
       ```
   
 * This works great. All except the last post. I cannot get it to display the content
   for the last post even though if I echo $serv_article it will print out with 
   the correct id just fine. The shortcode will not display the last post. I tried
   reordering the post to make sure it wasn’t just the post itself, but it always
   does it for the last post only. I even tried adding an extra element to the array,
   so the last post id wasn’t the end, and it still would not display the content
   of the last post in the while loop.
 * Any ideas what could be going on?
    Here’s the page this is running on: [http://chiseledimages.com/alpha/concathy/services/](http://chiseledimages.com/alpha/concathy/services/)
   Link to screenshot of what my source code looks like in Firebug: [http://s14.postimg.org/5ekr8cjhd/Capture.jpg](http://s14.postimg.org/5ekr8cjhd/Capture.jpg)(
   <– updated with extra blank div as described below)
 * thanks
 * **Update. I ended up adding an extra service post-type post and then limiting
   the while loop with a counter. So even though it still dynamically generates 
   7 divs that are hidden, there are only 6 excerpts that are displayed at the bottom.
   This has all the links working as the last displayed post is not actually the
   last post.
    Of course this is obviously just duct-tape and something I’m going
   to have to explain to my client so they don’t erase my blank post, so I’d still
   love a fix if possible.
 * [https://wordpress.org/plugins/post-content-shortcodes/](https://wordpress.org/plugins/post-content-shortcodes/)

The topic ‘dynamic variable issues in theme’ is closed to new replies.

 * ![](https://ps.w.org/post-content-shortcodes/assets/icon-256x256.png?rev=979726)
 * [Post Content Shortcodes](https://wordpress.org/plugins/post-content-shortcodes/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-content-shortcodes/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-content-shortcodes/)
 * [Active Topics](https://wordpress.org/support/plugin/post-content-shortcodes/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-content-shortcodes/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-content-shortcodes/reviews/)

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [post-content](https://wordpress.org/support/topic-tag/post-content/)

 * 0 replies
 * 1 participant
 * Last reply from: [everything_is_fine](https://wordpress.org/support/users/chiseledimages/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/dynamic-variable-issues-in-theme/)
 * Status: not resolved