WordPress Category Intersections Revisited

WordPress has included native support for intersections since (I think) version 2.3. Unfortunately, however, robust post retrieval support is only available for tags (eg. tag=A,B retrieves the union of “A” and “B”; tag=A+B retrieves the intersection of “A” and “B”).

Categories still require a hack, and the old plugins for this of course now no longer work.

To get intersection working, try adding the following line before the loop:

<?php <span style="color: #ff0000;">if ($_GET['cat']) query_posts(array('category__and'=>preg_split('/[\s,]+/',$_GET['cat'])));</span> ?>
<?php while( have_posts()) : the_post(); ?>

This applies an intersection to any list of categories separated by space, comma, or “plus” signs in the request.

See Ryan Boren’s post on WordPress intersection and union taxonomies for details on the various forms of post retrieval queries now available.

Tags: , ,

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.50 out of 5)
Loading ... Loading ...

Possibly Related:


One Response to “WordPress Category Intersections Revisited”

  1. WordPress Category Intersections Revisited | blog.arithm Says:

    [...] link: WordPress Category Intersections Revisited | blog.arithm Comments0 Leave a Reply Click here to cancel [...]

Leave a Reply