recent posts by tag(custom field)
-
I am trying to list my recent posts by tag. The trick is that my “tag” is a custom field. I have tried about 13 different code combinations, from
<?php query>to$posts-arrayand nothing seems to work. I have also browsed the forums and found others trying to do the same thing, but never with their custom field as the tag. I really don’t want to use a plugin if at all possible. Here’s the code I have gotten to work closest:<?php $args=array( 'numberposts' =>5, 'tag' => 'gary-alexander', 'orderby' =>'post_date', 'order' => 'DESC', ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo 'Recent News:'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; } //if ($my_query) wp_reset_query(); // Restore global post data stomped by the_post(). ?>Of course, instead of “gary-alexander” I need to replace it with a call to the custom field. I know for sure that the code to call the correct custom field is
<?php $key="member-name"; echo_get_post_meta($post->ID, $key, true); ?>
That code will without a doubt pull “gary-alexander” or whatever the person’s name I’m trying to pull. But when I plug this code into the code above after'tag' =>it displays nothing. I am SO CLOSE, any help is appreciated!!
The topic ‘recent posts by tag(custom field)’ is closed to new replies.