Title: Displaying Data in Shordcode
Last modified: August 2, 2017

---

# Displaying Data in Shordcode

 *  Resolved [Layson](https://wordpress.org/support/users/glennlaysonjr/)
 * (@glennlaysonjr)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/displaying-data-in-shordcode/)
 * I have been trying to figure out why
 * `$cover_img = get_post_meta( $post->ID, 'dc_sermons_dc_cover_img', true );`
 * Isn’t displaying in my shortcode loop. The shortcode is on the home page if that
   matters. Any ideas?
 * Here is my shortcode:
 *     ```
       add_shortcode( 'sermon-hub', 'dc_simple_shortcode' );
       function dc_simple_shortcode( $atts ) {
           ob_start();
           global $query;
   
           $query = new WP_Query( array(
               'post_type' => 'sermon_hub',
               'posts_per_page' => 3,
               'meta_key' => 'dc_sermons_dc_date',
               'orderby' => 'meta_value',
               'order' => 'DESC'
           ) );
   
   
           if ( $query->have_posts() ) { ?>
               <div class="dc-grid" style="width:100%; max-width:1020px; padding-top:25px;">
                   <?php while ( $query->have_posts() ) : $query->the_post(); ?>
                   <div class="dc-col-1-3 blurb-ripple-out" style="position:relative;">
                                 <div class="dc-post-container" style="<?php
                                           $show_shadow = dcoptions_get_option( 'short_shadow' );
                                           if ( $show_shadow == 'false') {
                                               echo 'box-shadow:none !important; -webkit-box-shadow:none; -moz-box-shadow:none; -o-box-shadow:none; border-radius: 0px;';
                                           }?> background-color:<?php echo dcoptions_get_option( 'short_box_bg' ); ?>;">
                                     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                     <?php
                                               $cover_img =  get_post_meta( $post->ID, 'dc_sermons_dc_cover_img', true );
                                               $default_img = dcoptions_get_option( 'default_sermon_image' );
                                               $site_url = get_site_url();
                                           if ( !empty($cover_img) ) {
                                               echo '<img style="border-radius:8px;" class="sermon_cover_image" src="'. $cover_img . '" />';
                                           } else if ( !empty($default_img) ) { 
                                               echo '<img style="border-radius:8px;" src="'. $default_img .'" />';
                                           } else {
                                               echo '<img style="border-radius:8px;" src="'. $site_url .'/wp-content/plugins/sermon-hub-plugin/img/default-sermon-img.jpg" />';
                                           } ?>
                                     </a>
                                     <div style="text-align:center;
                                        <?php
                                           $show_player = dcoptions_get_option( 'short_play' );
                                           if ( $show_player == 'false') {
                                               echo 'display:none !important;';
                                           } else { 
                                               echo '';
                                           }?>"><a href="<?php the_permalink(); ?>"><span class="dc-player-icon"></span></a></div>
                                     <div class="dc-echo-post-data-a" style="">
                                         <h2 style="text-align:center; <?php
                                           $show_details = dcoptions_get_option( 'short_title' );
                                           if ( $show_details == 'false') {
                                               echo 'display:none !important;';
                                           } else { 
                                               echo '';
                                           }?>"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                                           <div style="text-align:center; <?php
                                           $show_details = dcoptions_get_option( 'short_preacher' );
                                           if ( $show_details == 'false') {
                                               echo 'display:none !important;';
                                           } else { 
                                               echo '';
                                           }?>">
   
                                               <?php
                                               $terms = get_the_terms( $post->ID, 'preacher', true );
   
                                               if ( empty($terms)) {
                                                   echo '';
                                               } else if( $terms && ! is_wp_error( $terms ) )
                                               {
                                                   foreach( $terms as $term )
                                                   {
                                                       echo '<span>by ' . esc_attr( $term->name ) . '</span> ';            
                                                   }
                                               } ?>
                                           </div>
   
                                     </div>
                                  </div>
                               </div>            
                   <?php endwhile;
                   wp_reset_postdata(); ?>
               </div>
               <style>
   
               .blurb-ripple-out .dc-player-icon:before {
                   border: <?php echo dcoptions_get_option( 'archive_play_button' ); ?> solid 6px;
               }
               .dc-player-icon {
                   background-color: <?php echo dcoptions_get_option( 'archive_play_button' ); ?>;
               }
   
                <?php
                $show_shadow = dcoptions_get_option( 'short_shadow' );
                if ( $show_shadow == 'false') {
                   echo '
                   .dc-post-container img {
                   border-radius: 10px !important;
                   }
                   ';
                   } 
               ?> 
               @media all and (min-width: 768px) and (max-width: 1100px) {
                   [class*="dc-col-"] {
                       width: 33.33% !important;
                       padding-left: 0px !important;
                       padding-bottom: 0px !important;
                   }
               }
               </style>
           <?php $myvariable = ob_get_clean();
           return $myvariable;
           }
       }
       ```
   

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

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/displaying-data-in-shordcode/#post-9374628)
 * Try using `get_the_ID()` instead of `$post->ID`.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 10 months ago](https://wordpress.org/support/topic/displaying-data-in-shordcode/#post-9374634)
 * On top of what Justin said, have you confirmed that that meta key matches what’s
   saved to the post meta and the database? Possible that’s not quite matched up
   properly.
 *  Thread Starter [Layson](https://wordpress.org/support/users/glennlaysonjr/)
 * (@glennlaysonjr)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/displaying-data-in-shordcode/#post-9374648)
 * Its the simple things in life. lol
 * Thanks Justin for the fast reply. That worked!
 * G
    -  This reply was modified 8 years, 10 months ago by [Layson](https://wordpress.org/support/users/glennlaysonjr/).

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

The topic ‘Displaying Data in Shordcode’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Layson](https://wordpress.org/support/users/glennlaysonjr/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/displaying-data-in-shordcode/#post-9374648)
 * Status: resolved