WordPress Custom Query

I have posts that use a custom field for start date and end date.
query_posts returns an array of posts that exist in the category I’m filtering.
How do I query posts using this custom field that has date i.e. 03/11/2010 and not the full array. Pagination works on the full array so it returns all posts. I can use an if else to only show the posts newer that today, then pagination doesn’t work.
Would I have to build a custom mysql query?

3 Answers
3

<?php

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

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

 ?>

Then you would access $pageposts as an object

Leave a Comment