Support » Fixing WordPress » Adding post meta to custom short tag

  • Resolved narkiej

    (@narkiej)


    I have created a short tag that pulls in a specific post. Everything works great But I can’t get get_post_meta to function. Could you tell me why it isn’t displaying please?

    <?php function sleeve_shortcode( $atts )
    {
    extract(shortcode_atts(array(
            'id' => '',
    	), $atts));
    	//The Query
    	query_posts('showposts=1&p=' . $id . '');
    	//The Loop
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    		echo '<div class="relative" style="margin-bottom:10px; height:550px;">';
    		echo ''; echo
    	the_post_thumbnail( array(550,550, true) );
    echo'';
    		echo '<div class="goliath icecoldman">';
    		echo '<div class="title"><h1><a href="'; echo the_permalink(); echo '">'; echo the_title(); echo '</a></h1>';
    		echo '<div class="liney"></div>';
    		echo '<h2><a href="'; echo the_permalink(); echo '">'; echo get_post_meta($post->ID, 'artist_name', $single = true); echo '</a></h2>';
    		echo '<div class="text">'; echo ShortenExcerpt(the_excerpt()); echo'</div>';
    		echo '</div></div></div>';
    
    	endwhile; else:
    	endif;
    
    	//Reset Query
    	wp_reset_query();
    }
    add_shortcode('sleeve', 'sleeve_shortcode'); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • TO make it easier, this is the bit that isn’t working:
    echo '<h2><a href="'; echo the_permalink(); echo '">'; echo get_post_meta($post->ID, 'artist_name', $single = true); echo '</a></h2>';

    Finally sorted by adding: global $post;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding post meta to custom short tag’ is closed to new replies.