[resolved] Links list with items from two categories (4 posts)

  1. KenBroman
    Posted 5 years ago #

    I'm looking for a way to make a list of links only if it has two specific categories. For instance an item that has both Catagory A and Catagory B, but not every item in Catagory A and Catagory B.

    I've searched around in the codex and online but I can't figure out how this might be accomplished as my PHP skills aren't very good yet.

    Any help would be appreciated.

  2. MichaelH
    Posted 5 years ago #

    Didn't test this much but replace 10,14 with your two link category IDs

    $tsql = "SELECT l.link_id FROM $wpdb->links l INNER JOIN $wpdb->term_relationships tr ON (l.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)";
    $tsql .= " WHERE tt.taxonomy = 'link_category' AND t.term_id IN ('4','10')";
    $tsql .= " GROUP BY l.link_id HAVING count(l.link_id) = 2"; // 2 is number of categories we're looking for
    $link_ids = $wpdb->get_col($tsql);
      'include' => implode(',', $link_ids),
      'categorize'=> 0,
      'title_li'=>'links in cat 4 AND 10'

    How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?

  3. KenBroman
    Posted 5 years ago #

    Thanks, I will give that a try.

  4. KenBroman
    Posted 5 years ago #

    That seems to be working perfectly. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic