Title: Post loop and shortcodes
Last modified: February 1, 2020

---

# Post loop and shortcodes

 *  Resolved [antonie7](https://wordpress.org/support/users/antonie7/)
 * (@antonie7)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/)
 * Hi,
 * Mayby I’m overlooking something, but it seems my custom post type loop doesn’t
   support the use of shortcodes. Here’s my php:
 *     ```
       <?php
   
       $args = array(
           'post_status' => 'publish',
           'post_type' => 'sections',
           'meta_key' => 'display_order',
           'orderby' => 'meta_value_num',
           'order' => 'ASC',
           'showposts' => '50',
       );
   
       $posts = get_posts($args);
       foreach($posts as $post): ?>
   
       <section class='segment-wrapper'  style="background-color:<?php the_field('bgcolor'); ?>;color:<?php the_field('txcolor'); ?>;">
   
       <div class='text-inside'>
   
       <?php echo ($post->post_content); ?>
   
       </div>
       </section>
   
       <?php endforeach; ?>
       ```
   
 * So, this loop works fine except for the shortcodes used in the content of the
   returned posts.
 * Any suggestions? Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [mzaheerdad](https://wordpress.org/support/users/zaheerdad/)
 * (@zaheerdad)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/#post-12388366)
 * Hi,
 * Use the following for displaying contents,
    `echo do_shortcode( $content );`
 *  [Little Package](https://wordpress.org/support/users/littlepackage/)
 * (@littlepackage)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/#post-12388509)
 * A little different from what @zaheerd says, I’m also wondering why you use
 * `<?php echo ($post->post_content); ?>`
 * and why you’re not using
 * `<?php the_content(); ?>`
 * instead. For better performance, I recommend taking a look at the [code structure here (WP codex)](https://developer.wordpress.org/reference/functions/get_posts/#comment-1189)
   and mimicking it. Definitely use wp_reset_postdata() If you’re going further 
   with this template, you could be missing out on nice WP built-ins by not using
   setup_postdata().
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/#post-12388968)
 * If you want to use `the_content()` instead, because you are not using a standard
   WP loop, you need to use `setup_postdata()` before using any template tags like`
   the_content()`, `the_title()`, etc.
 * `do_shortcode()` will expand shortcodes, but post content is filtered for more
   than just shortcodes. If you want to ensure output is just like what we see from
   a standard WP loop, either use `the_content()` or do something like `echo apply_filters('
   the_content', $post->post_content );`
 *  Thread Starter [antonie7](https://wordpress.org/support/users/antonie7/)
 * (@antonie7)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/#post-12398533)
 * Thanks for clarifying! Using `<?php echo ($post->post_content); ?>` was a rookie
   mistake on my part, I guess.
    The loop works perfectly now using the suggested
   syntax.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Post loop and shortcodes’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 4 participants
 * Last reply from: [antonie7](https://wordpress.org/support/users/antonie7/)
 * Last activity: [6 years, 4 months ago](https://wordpress.org/support/topic/post-loop-and-shortcodes/#post-12398533)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
