Posted By

rickfu on 06/27/09


Tagged

wordpress wp


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

irishsk
joelhaus


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


 / Published in: PHP
 

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

  1. <?php
  2. /*
  3. Template Name: Custom query
  4. */
  5.  
  6. $querystr = "
  7. SELECT wposts.*
  8. FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
  9. WHERE wposts.ID = wpostmeta.post_id
  10. AND wpostmeta.meta_key = 'tag'
  11. AND wpostmeta.meta_value = 'email'
  12. AND wposts.post_status = 'publish'
  13. AND wposts.post_type = 'post'
  14. ORDER BY wposts.post_date DESC
  15. ";
  16.  
  17. $pageposts = $wpdb->get_results($querystr, OBJECT);
  18.  
  19. if ($pageposts):
  20. foreach ($pageposts as $post):
  21. setup_postdata($post);
  22. // Display your post info. For exemple: the_title();the_exerpt();
  23. endforeach;
  24. endif;
  25.  
  26. ?>

Report this snippet  

You need to login to post a comment.