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) { extract(shortcode_atts(array( 'type' => '', 'limit' => '10', 'ucategory' => '', ),$atts)); //The Query query_posts('post_type=ulisting&posts_per_page='.$limit.'&user-type='.$ucategory.'&orderby=title&order=ASC'); 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="http://webpages.leeu.edu/'; echo get_post_meta($post->ID, "username", true); echo '"><img src="http://www.gravatar.com/avatar/09c326816694a26d129bd1c2f90c4b36?s=50" alt="Member avatar" class="avatar user-1331-avatar" width="50" height="50" /></a> </div> <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> </div> <div class="action"></div> <div class="clear"></div> </li>'; endwhile; else: endif; //Reset Query wp_reset_query(); echo "</ul>"; echo "</div>"; } add_shortcode('usersList', 'customPostType_shortcode');
- The topic ‘Passing Custom Field Values inside Shortcode’ is closed to new replies.