Skip to content

Instantly share code, notes, and snippets.

@jegtnes
Created March 9, 2013 11:11
Show Gist options
  • Save jegtnes/5123868 to your computer and use it in GitHub Desktop.
Save jegtnes/5123868 to your computer and use it in GitHub Desktop.
Example of filtering by multiple categories and tags with a custom WP Query
<?php
$categories = $_GET( 'categories' );
$tags = $_GET( 'tags' );
$query = new WP_Query(
array( 'cat' => $categories ),
array( 'tags' => $tags )
);
while ( $query->have_posts() ) :
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
?>
<a href="/?tags=cake,cookie,baking&categories=14,92,16">Link to custom query</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment