Return to Snippet

Revision: 22536
at January 14, 2010 12:23 by davebowker

Initial Code
<ul class="feature-images">
		global $wpdb;
		$sql = "SELECT wposts.*
			FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
			WHERE wposts.ID = wpostmeta.post_id
			AND wpostmeta.meta_key = 'lab-image'
			AND wposts.post_status = 'publish'
			AND wposts.post_type = 'post'
			ORDER BY wposts.post_date DESC LIMIT 3";
		$pageposts = $wpdb->get_results($sql, OBJECT);
		$output = $pre_HTML;
		foreach ($pageposts as $post) : setup_postdata($post);  ?>
			<li><a href="<?php the_permalink(); ?>" title="Link to <?php the_title(); ?>">
			<img src="<?php echo get_post_meta($post->ID, "lab-image", $single = true); ?>" alt="<?php the_title(); ?>" /></a></li>
		<?php endforeach; ?>

Initial URL

Initial Description

Initial Title
WordPress retrieve custom field from outside the loop

Initial Tags
php, wordpress, query

Initial Language