Support » Fixing WordPress » Passing Custom Field Values inside Shortcode

  • Okay below you will see my first attempt at a shortcode. What I am trying to do is call in a list of custom posts (named “ulisting”). Instead of a normal URL to take you to a single-instance of the post type, I want to throw in a custom field value. However, the custom field doesn’t seem to display. What am I doing wrong?

    function customPostType_shortcode($atts) {
            'type' => '',
            'limit' => '10',
    		'ucategory' => '',
            //The Query
    		echo	"<div id=\"members-dir-list\" class=\"members dir-list\">";
    		echo	"<ul id=\"members-list\" class=\"item-list\">";
            //The Loop
           if ( have_posts() ) : while ( have_posts() ) : the_post();
                    echo  '<li>
    			<div class="item-avatar">
    				<a href="'; echo get_post_meta($post->ID, "username", true); echo '"><img src="" alt="Member avatar" class="avatar user-1331-avatar" width="50" height="50" /></a>
    			<div class="item">
    				<div class="item-title">
    					<a href="'; echo get_post_meta($post->ID, "username", true); echo '">'; echo the_title(); echo '</a><br />
                        <span class="update">'; echo the_content(); '</span>
    			<div class="action"></div>
    			<div class="clear"></div>
            endwhile; else:
            //Reset Query
    		echo	"</ul>";
    		echo	"</div>";
    add_shortcode('usersList', 'customPostType_shortcode');
  • The topic ‘Passing Custom Field Values inside Shortcode’ is closed to new replies.