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?