In my header.php, I’m using get_pages() to grab the top-2-level pages (parentless pages) to generate a custom menu. Problem is that this affects The Loop within my single.php template (when displaying the current post); it gives me a 404 error.
Taking the get_pages() call out of my header.php will allow me to view my post correctly, but I need to generate my own header (wp_list_pages doesn’t work for me).
So it’s clear that get_pages affects the loop (perhaps resets it), so is there a WordPress query to grab all pages of the top 2 levels (depth of 2) and be able to exclude page ids, all without affecting The Loop? Here are the arguments from my get_pages that I need matched with the new query:
$args = array( 'sort_order' => 'ASC', 'sort_column' => 'menu_order', 'hierarchical' => 0, 'parent' => 0, 'post_type' => 'page', 'post_status' => 'publish', 'exclude' => '41,29' );
Within each page object returned, I check to see if it has children, and calls another query to grab these children, generating a dropdown for this page item.
I can’t use wp_list_pages because it doesn’t allow me to iterate through each returned item to insert a second-level list (dropdown).
- The topic ‘Trying to grab top-2-level pages without affecting The Loop’ is closed to new replies.