Forums

[resolved] Adding post meta to custom short tag (3 posts)

  1. narkiej
    Member
    Posted 1 year ago #

    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'); ?>
  2. narkiej
    Member
    Posted 1 year ago #

    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>';

  3. narkiej
    Member
    Posted 1 year ago #

    Finally sorted by adding: global $post;

Topic Closed

This topic has been closed to new replies.

About this Topic