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


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.