• niels

    (@nielswayneparkerkentcom)


    Hi, I want to filter my post by using a custom select query.
    I use this query:

    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
    	LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
    	LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
    	LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE
    	$wpdb->term_taxonomy.taxonomy = 'category'
    	AND
         ($wpdb->term_taxonomy.term_id = 1 OR $wpdb->term_taxonomy.term_id = 2)
    AND
    
    ($wpdb->term_taxonomy.term_id = 5 OR $wpdb->term_taxonomy.term_id = 6)
    
    LIMIT 4
    ";

    But it gives back no results, what am I doing wrong?

    thx,

    Niels

Viewing 1 replies (of 1 total)
  • When debugging a query like this one, I always suggest that you start little and go bigger and bigger.

    Start with only your “select * from ” and add only one left join and see if the result is what you expect. Then add another element and so on.

    The thing is that you say you’re doing a “custom query” but there is no way to help you as we do not know what your query is doing. Debugging the way I told you is the best way to learn by yourself!

    I hope it helped!

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Select query’ is closed to new replies.