Every page is showing all blog posts (instead of page content)
-
I have been developing a site with a custom theme. It’s very simple and I’m using the block editor for the page content. At one point, I updated a page, went to reload it on the frontend and it displayed all of the blog posts as if it were the Posts page. Clicking around I saw that every single page on the site, except the homepage is showing all the posts listed instead of the page itself. I have reverted all recent changes to theme files one by one to no avail. I’ve removed all unnecessary theme files, tried renaming them by process of elimination, no result.
Pages are the only post type affected. Going directly to a blog post or an event post (from The Events Calendar plugin) properly displays that content.
Switching themes eliminates the problem.
Changing the permalink structure to either Numeric or Plain eliminates the problem, but I can’t leave it like that.
The theme is extremely simple. I’m at a total loss for why this is happening.
This issue did not follow any plugin updates or anything like that. I don’t think it was triggered by the change I was making to the page at the time. It must have happened before and I didn’t notice right away.
I appreciate any help, thank you!
-
For some reason, WP is interpreting a page request as an archive request. What permastruct are you using? It could be the wrong rewrite rule is matching the request. This can happen when there are numbers in the URL that are not date numbers.
The other possibility is WP_Query is getting query vars that cause it to query for a bunch of posts instead of the requested page. To see the query vars used, hook “pre_get_posts” and var_dump the passed object’s
$query_vars
array.@bcworkz thanks for the reply. My permalink structure is set to Post name. This problem happens with any permalink structure that includes %postname%.
Did the var_dump as suggested and got a very long result that I’m not really sure how to interpret. This is on a page called Contact with the post id 25.
array (size=57) 'post_status' => string 'any' (length=3) 'posts_per_page' => int 20 'offset' => int 0 'orderby' => string 'ID' (length=2) 'order' => string 'ASC' (length=3) 'post_type' => string 'wpcf7_contact_form' (length=18) 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'post_name__in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty /Users/johnnatoli/Local Sites/dlfny/app/public/wp-content/themes/dlfny/functions.php:90: array (size=65) 'numberposts' => int 1 'category' => int 0 'orderby' => string 'date' (length=4) 'order' => string 'desc' (length=4) 'include' => string '' (length=0) 'exclude' => string '' (length=0) 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'post_type' => string 'wp_global_styles' (length=16) 'suppress_filters' => boolean true 'offset' => int 0 'post_status' => array (size=1) 0 => string 'publish' (length=7) 'tax_query' => array (size=1) 0 => array (size=3) 'taxonomy' => string 'wp_theme' (length=8) 'field' => string 'name' (length=4) 'terms' => string 'dlfny' (length=5) 'posts_per_page' => int 1 'ignore_sticky_posts' => boolean true 'no_found_rows' => boolean true 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'post_name__in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty /Users/johnnatoli/Local Sites/dlfny/app/public/wp-content/themes/dlfny/functions.php:90: array (size=51) 'year' => int 0 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'post_name__in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty /Users/johnnatoli/Local Sites/dlfny/app/public/wp-content/themes/dlfny/functions.php:90: array (size=56) 'post_status' => string 'publish' (length=7) 'post_type' => string 'wp_template' (length=11) 'posts_per_page' => int -1 'no_found_rows' => boolean true 'tax_query' => array (size=1) 0 => array (size=3) 'taxonomy' => string 'wp_theme' (length=8) 'field' => string 'name' (length=4) 'terms' => string 'dlfny' (length=5) 'post_name__in' => array (size=2) 0 => string 'home' (length=4) 1 => string 'index' (length=5) 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty /Users/johnnatoli/Local Sites/dlfny/app/public/wp-content/themes/dlfny/functions.php:90: array (size=56) 'post_status' => string 'publish' (length=7) 'post_type' => string 'wp_template' (length=11) 'posts_per_page' => int -1 'no_found_rows' => boolean true 'tax_query' => array (size=1) 0 => array (size=3) 'taxonomy' => string 'wp_theme' (length=8) 'field' => string 'name' (length=4) 'terms' => string 'dlfny' (length=5) 'post_name__in' => array (size=2) 0 => string 'home' (length=4) 1 => string 'index' (length=5) 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty /Users/johnnatoli/Local Sites/dlfny/app/public/wp-content/themes/dlfny/functions.php:90: array (size=68) 'numberposts' => int 5 'category' => int 0 'orderby' => string 'menu_order' (length=10) 'order' => string 'ASC' (length=3) 'include' => array (size=0) empty 'exclude' => array (size=0) empty 'meta_key' => string '' (length=0) 'meta_value' => string '' (length=0) 'post_type' => string 'nav_menu_item' (length=13) 'suppress_filters' => boolean true 'post_status' => string 'publish' (length=7) 'output' => string 'ARRAY_A' (length=7) 'output_key' => string 'menu_order' (length=10) 'nopaging' => boolean true 'tax_query' => array (size=1) 0 => array (size=3) 'taxonomy' => string 'nav_menu' (length=8) 'field' => string 'term_taxonomy_id' (length=16) 'terms' => int 17 'update_post_term_cache' => boolean false 'posts_per_page' => int 5 'ignore_sticky_posts' => boolean true 'no_found_rows' => boolean true 'error' => string '' (length=0) 'm' => string '' (length=0) 'p' => int 0 'post_parent' => string '' (length=0) 'subpost' => string '' (length=0) 'subpost_id' => string '' (length=0) 'attachment' => string '' (length=0) 'attachment_id' => int 0 'name' => string '' (length=0) 'pagename' => string '' (length=0) 'page_id' => int 0 'second' => string '' (length=0) 'minute' => string '' (length=0) 'hour' => string '' (length=0) 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' (length=0) 'tag' => string '' (length=0) 'cat' => string '' (length=0) 'tag_id' => string '' (length=0) 'author' => string '' (length=0) 'author_name' => string '' (length=0) 'feed' => string '' (length=0) 'tb' => string '' (length=0) 'paged' => int 0 'preview' => string '' (length=0) 's' => string '' (length=0) 'sentence' => string '' (length=0) 'title' => string '' (length=0) 'fields' => string '' (length=0) 'menu_order' => string '' (length=0) 'embed' => string '' (length=0) 'category__in' => array (size=0) empty 'category__not_in' => array (size=0) empty 'category__and' => array (size=0) empty 'post__in' => array (size=0) empty 'post__not_in' => array (size=0) empty 'post_name__in' => array (size=0) empty 'tag__in' => array (size=0) empty 'tag__not_in' => array (size=0) empty 'tag__and' => array (size=0) empty 'tag_slug__in' => array (size=0) empty 'tag_slug__and' => array (size=0) empty 'post_parent__in' => array (size=0) empty 'post_parent__not_in' => array (size=0) empty 'author__in' => array (size=0) empty 'author__not_in' => array (size=0) empty
bizarrely, when I switch themes then Live Preview the broken theme, it works fine in the preview
You got the contact form query vars instead of those of the main query. I wasn’t explicit enough in my request, apologies. Place the var_dump line in a conditional:
add_action('pre_get_posts', function( $query ) { if ( $query->is_main_query()) { var_dump( $query->query_vars ); } }, 999 );
For a /contact/ request with %postname% permastruct, the “pagename” query var should be assigned “contact”. Everything else should be 0 or empty. FYI, the
999
helps ensure we see the final version after other code may have possibly altered the query.You could also echo out the global
$wp_query->request
value on the template being used to see the actual SQL query being used (or use the Query Monitor plugin). A single page query ought to look something likeSELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = '25') AND wp_posts.post_type = 'page' ORDER BY wp_posts.post_date DESC
Where things deviate from the expected helps to narrow down where things may have gone wrong.
Another place to check are the query vars passed to the “request” filter. There should be little else than
"pagename" => "contact"
. This filter fires relatively early. If the vars are incorrect here, the request was matched to the wrong rewrite rule, just about the first thing that happens. The SQL output from the template is the last thing before making a query. “pre_get_posts” is somewhere in between “request” and the SQL.To better help understand the entire parsing and request process, review Query Overview. It may help you determine where in the process things are going wrong. You can temporarily add debug code anywhere needed to help determine the root cause. Filter and action hooks are best, but temporarily altering core code is acceptable if need be.
- The topic ‘Every page is showing all blog posts (instead of page content)’ is closed to new replies.