• Resolved itsjohn

    (@itsjohn)


    i’ve been doing customized sql queries and I’m stumped one thing. I can’t seem to query both publish and future at the same time, it queries the future and repetitively posts that to however much I set the limit at.

    currently this is what i have,

    $querying = $wpdb->get_results("
                          SELECT *
                          FROM $wpdb->posts, $wpdb->terms, $wpdb->term_relationships, $wpdb->term_taxonomy
                          WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id
                            AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
                            AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
                            AND $wpdb->posts.post_status = 'publish'
                            OR $wpdb->posts.post_status = 'future'
                            AND $wpdb->terms.term_id IN (1,2,3,4)
                            ORDER BY $wpdb->posts.post_date DESC
                            LIMIT 5
                        ");

Viewing 2 replies - 1 through 2 (of 2 total)
  • looks like you’re missing some parens:

    …AND ( $wpdb->posts.post_status = ‘publish’
    OR $wpdb->posts.post_status = ‘future’ )…

    Anytime you’re mixing ANDs and ORs, you’ll generally need ’em.

    Thread Starter itsjohn

    (@itsjohn)

    awesome, thanks man!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sql queries’ is closed to new replies.