• Resolved kenbroman

    (@kenbroman)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Didn’t test this much but replace 10,14 with your two link category IDs

    <?php
    $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);
    $args=array(
      'include' => implode(',', $link_ids),
      'categorize'=> 0,
      'title_li'=>'links in cat 4 AND 10'
    );
    wp_list_bookmarks($args);
    ?>

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

    Thread Starter kenbroman

    (@kenbroman)

    Thanks, I will give that a try.

    Thread Starter kenbroman

    (@kenbroman)

    That seems to be working perfectly. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Links list with items from two categories’ is closed to new replies.