Custom query to select posts with term in category (1 post)

  1. d910qf
    Posted 7 years ago #

    Hi - I am using this query

    SELECT * FROM $wpdb->posts
    INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = $termID
    AND $wpdb->term_taxonomy.taxonomy = '$taxonomy'
    AND $wpdb->posts.post_status = 'publish'";

    To select all posts with a particular term/tag (from ANY taxonomy, not just tags or categories).

    I would like to specify a category as well, but can't get the query I need. Does anyone know if it is possible to select all posts in a category that are linked to a particular term?


Topic Closed

This topic has been closed to new replies.

About this Topic