Return to Snippet

Revision: 15220
at June 27, 2009 13:21 by rickfu


Initial Code
<?php
/*
Template Name: Custom query
*/

 $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = 'tag'
    AND wpostmeta.meta_value = 'email'
    AND wposts.post_status = 'publish'
    AND wposts.post_type = 'post'
    ORDER BY wposts.post_date DESC
 ";

 $pageposts = $wpdb->get_results($querystr, OBJECT);

if ($pageposts):
  foreach ($pageposts as $post):
    setup_postdata($post);
    // Display your post info. For exemple: the_title();the_exerpt();
  endforeach;
endif;

?>

Initial URL
http://www.wprecipes.com/how-to-display-post-based-on-custom-fields-with-a-custom-query

Initial Description


Initial Title
How to: Display post based on custom fields with a custom query

Initial Tags
wordpress

Initial Language
PHP