WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom taxonomy, and that works.

But here is the problem; I have created an archive page, which in the url gets e.g. this: ?category=23. Then, in functions.php, I do this:

function add_inspiration_category( $q ) {
    if (is_post_type_archive('inspiration') && !is_admin()) {

        $category_id = $_GET['category'];
        if (!empty($category_id)) {
            $q->set('tax_query', array(
                    'taxonomy' => 'inspiration-taxonomy',
                    'field' => 'id',
                    'terms' => $category_id

    return $q;
add_filter('parse_query', 'add_inspiration_category');

So, basically I'm filtering the archive pages result based on the id in the url. This works, except when I'm filtering on a category, the main menu dissapears from the header. If I remove the ?category=23 from the url or comment out the section above where I set the tax_query, it works as expected again. Anyone know what this is?

share|improve this question
up vote 1 down vote accepted

You are applying that filter to every query on the pages matching the conditions or that if. You need to restrict this to only the main query and make sure that the conditions are only operating on the $q query passed into the function.

if ($q->is_main_query() 
   && $q->is_post_type_archive('inspiration') 
   && !is_admin()) {
share|improve this answer
Thank you, that worked! – ptf Feb 8 '14 at 15:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.