• WHYYY in God’s name does the following custom query not return any posts? It is intended to grab all posts out of category ‘9’ and sort them by date (a meta field, not post date).

    ` $querystr =

    SELECT $wpdb->posts.*
    FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id)
    WHERE $wpdb->postmeta.meta_key = ‘date’
    AND $wpdb->posts.post_status = ‘publish’
    AND $wpdb->posts.post_type = ‘post’
    AND $wpdb->post2cat.category_id IN (9)
    ORDER BY $wpdb->postmeta.meta_value DESC
    “;

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

    if ($pageposts):

    foreach ($pageposts as $post):

    setup_postdata($post);`

    It is taken practically right out of a Codex example. I can’t figure it out, I’ve been combing through it all day?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Query Returns Nothing?’ is closed to new replies.