0

I'm working on a WordPress site with 2 custom post types. For some reason that I cannot figure out, my nav menus are not displaying on my category.php pages. The header.php file is being called and rendered just fine, and the Nav menu works on all other pages. So, I believe the problem is not to do with the WP Nav menu, but with the query.

I had the same issue with my footer Nav menu. I found others who solved this problem by resetting the query to NULL just before footer.php is called. This works, though it seems like a poor solution.

Of course, I cannot do this before header.php is called because I need to use the query in order to fetch and render all the content on the page. I'm really stuck here. Has anyone else had this problem?

--- UPDATE ---

This is working, and is based on the same principle mentioned above: reset the query, get the nav menu.

// store the query in a variable    
$query_store = $wp_query;

// reset the query
$wp_query = NULL;
$wp_query = new WP_Query(array('post_type' => 'projects'));

// get the header
get_header();

// retrieve the query from storage, use it
$wp_query = $query_store;

I am also sorting by custom meta_values. I am able to pass the active category to the new query using this method:

// get the current category, pass it to the new query arguments below
if (is_category('category-one')) { $category_name = 'category-one'; }
if (is_category('category-two')) { $category_name = 'category-two'; }

However, this presents another issue: the class list (set in header.php) no longer contains the category class (which affects my CSS).

My original question still remains: is there a cleaner way to do this?

2 Answers 2

0

You have to reset all the postdata array and query array, for that you can use below links.

[1] http://codex.wordpress.org/Function_Reference/wp_reset_postdata

[2] http://codex.wordpress.org/Function_Reference/wp_reset_query

thanks.

0

have you tried adding the 2 functions below at the end of every wp loop you have in the page?

wp_reset_postdata();
wp_reset_query();

1
  • Thanks! I tried this, no dice. This is what I currently have just before get_footer(); is called: $wp_query = NULL; $wp_query = new WP_Query(array('post_type' => 'projects'));
    – printr
    Oct 14, 2013 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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