Get Posts by Custom Field
-
I’m trying to get posts with a custom field. Currently I’m using the PHP below which works but outputs ALL of them. I want to only output the latest post, but when I use the query posts in the first line it makes it disappear.
<?php query_posts($query_string); query_posts('showposts=1'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); $customField = get_post_custom_values("lead-story"); if (isset($customField[0])) { //Custom field is set, display post info $values = get_post_custom_values("Image"); if ( $values != '' ) { echo '<a href="'; the_permalink(); echo '" rel="bookmark" title="Permanent Link to '; the_title(); echo '"><img src="'; echo get_option('home'); echo '/wp-content/uploads/'; echo $values[0]; echo '" alt="" id="leadpic" class="feature-img" /></a>'; } echo '<a href="'; the_permalink(); echo '" rel="bookmark" title="Permanent Link to '; the_title(); echo '" class="lead-story-title">'; the_title(); echo '</a><br /><span class="smalltext">'; the_time('F jS, Y'); echo '</span><p>'; echo substr(get_the_excerpt(), 0, 150); echo '...<br /><a href="'; the_permalink(); echo '" rel="bookmark" title="Permanent Link to '; the_title(); echo '">Read More »</a></p>'; } endwhile; endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get Posts by Custom Field’ is closed to new replies.