• Hello,

    I have 2 post types, “news” and the regular “post”. I want to merge these 2, so I build a WP_Query:

    $news = new WP_Query(array("post_type" => array("news", "post"), "showposts" => 2));

    That works very well. But; from “post” I want only items places in categorie 10, so I tried this:

    $news = new WP_Query(array( "post_type" => array("news", "post"), "showposts" => 2, "category__in" => array(10) ));

    Results: nothing for “news” gets displayed because none of those messages apply the the “category__in” selection. How do I get category__in to apply only to posts?

Viewing 1 replies (of 1 total)
  • Thread Starter nielsvanrenselaar

    (@nielsvanrenselaar)

    Well, I now have something working, so for people in need:

    $querystr = "
    SELECT $wpdb->posts.*
    FROM $wpdb->posts, $wpdb->term_relationships
    WHERE $wpdb->posts.post_status = 'publish'
    AND $wpdb->term_relationships.object_id = $wpdb->posts.ID
    AND ( ($wpdb->posts.post_type = 'post' AND $wpdb->term_relationships.term_taxonomy_id = 10) OR ($wpdb->posts.post_type = 'news'))
    AND $wpdb->posts.post_date < NOW()
    ORDER BY $wpdb->posts.post_date DESC
    LIMIT 2
    ";
    
    $pageposts = $wpdb->get_results($querystr, OBJECT);

    Where 10 is your term ID

Viewing 1 replies (of 1 total)
  • The topic ‘Merge 2 post types from different categories’ is closed to new replies.