• i tried to make a custom select query to get a post based on 2 categories.
    The code that i get from wordpress works for 1 category, but not 2.

    SELECT DISTINCT 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)
    			LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
    		WHERE $wpdb->term_taxonomy.taxonomy = 'category'
    			AND $wpdb->terms.name = '" . $selectedCategory . "'
    		ORDER BY wposts.ID DESC

    That’s the code that i’m using, but i don’t know how to add the 2nd category into the query.
    Please help..

  • The topic ‘Custom select query from 2 categories’ is closed to new replies.