• Hi, I’ve a custom taxonomy in a language and I would retrieve the posts from the same taxonomy but from another language. I’ve the IDs. My query is

    SELECT SQL_CALC_FOUND_ROWS posts.ID FROM posts INNER JOIN term_relationships ON (posts.ID = term_relationships.object_id) WHERE 1=1 AND ( term_relationships.term_taxonomy_id IN (3841) ) AND posts.post_type = ‘ads’ AND (posts.post_status = ‘publish’ OR posts.post_status = ‘private’) GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT 0, 10

    Into this

    SELECT SQL_CALC_FOUND_ROWS posts.ID FROM posts INNER JOIN term_relationships ON (posts.ID = term_relationships.object_id) WHERE 1=1 AND ( term_relationships.term_taxonomy_id IN (4061) ) AND posts.post_type = ‘ads’ AND (posts.post_status = ‘publish’ OR posts.post_status = ‘private’) GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT 0, 10

    Just change the taxonomy ID. I user the action “pre_get_posts” to manipulate this but I only get a OR statement like this

    SELECT SQL_CALC_FOUND_ROWS posts.ID FROM posts INNER JOIN term_relationships ON (posts.ID = term_relationships.object_id) WHERE 1=1 AND ( term_relationships.term_taxonomy_id IN (3841) OR term_relationships.term_taxonomy_id IN (4061) ) AND posts.post_type = ‘ads’ AND (posts.post_status = ‘publish’ OR posts.post_status = ‘private’) GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT 0, 10

    by passing this argument

    $taxquery = array(
    ‘relation’ => ‘OR’,
    array(
    ‘taxonomy’ => ‘ads’,
    ‘field’ => ‘id’,
    ‘terms’ => array( 4061)
    )
    );

    $query->set( ‘tax_query’, $taxquery );

    Can someone help me? Thanks

  • The topic ‘Modify the custom taxonomy id in the main query’ is closed to new replies.