I have resolved this issue after reviewing a get_posts()
function that was running in a template partial that was not using setup_postdata( $post )
at the start of the foreach
and closing out with a wp_reset_postdata()
after the foreach had completed.
This get_posts()
was corrupting the main loop array and causing it to fail on page.php and single.php.
Fixed get_posts function
// Simplified for ease of reading
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => 1,
);
$posts = get_posts( $args );
<?php if ( $posts ) : ?>
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
<!-- Post Content Output -->
<?php endforeach; wp_reset_postdata(); ?>
<?php endif; ?>
Related Posts:
- Getting only direct child pages in WordPress with get_pages
- Guidance with The Loop for CMS
- How can I loop into two different DIVS without repeating the DIVs
- WordPress loop specific thumbnail size
- Can’t load WP function into external function
- Custom category code not showing all posts
- How to hide all child pages with post_query?
- Populate editor with some content of a page with a page template
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- Syntax error when I try to insert my loop into an unordered list? [closed]
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Show About and Contact Us page when they’re clicked in the top menu.
- How to avoid duplicates when creating recent network posts
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Why in my theme I can’t see all the statics content under the posts?
- Get all posts as an array ID => Name
- home.php show blog posts as grid view
- Display child page content of a specific parent on home page
- List all anchor links on a page
- Toolbar Hidden in a Virtual Page
- Search.php gets metadata from first post
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- Check if current post in loop is last on current page
- Looping through dummy posts and showing them in the main index.php
- Display page content in different sections – based on page break block?
- Get current_post in reverse order with pagination
- Problems with the WordPress loop [closed]
- Create a custom theme-specific page, invisible in the admin-panel?
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- WP multisite network plugin fails to see classes loaded with spl autoload
- Adding Media button to only pages
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- How to handle parent and child pages?
- How do I remove blog entries from home page Twenty Eleven child theme?
- Pagination not working properly
- $_html is empty when var dumped
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- spliting posts into two columns
- Must Use Plugin Causing Query Error
- How to get to a specific position in wp_query?
- Differences when using the the_time and the_date functions
- Exclude posts from homepage having a specified tag
- Why is this Ajax not working?
- Advanced Custom Fields: Post Object – Not returning data [closed]
- How do I access the media settings
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Changing the template hierarchy
- How to speed up a wordpress function with multiple loops?
- Facebook “like” open graph meta in header.php
- Custom excerpt function re-factoring
- Limit get_pages to only show 5 items
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- using add_action for a header hook that has an additional parameter
- Custom php page outside the scope of my theme
- syntax issue on php 7.4
- How do I publish only one page to production after making changes on staging?
- custom shortcode will not display the wrapped content
- multiple if statements [closed]
- Custom Template 404 for specific custom post type
- How to select WooCommerce products by post_meta and order them
- How can I add pagination and how can I change thumbnail size?
- Displaying theme options in css
- max_input_vars: how many am I using?
- How to Display a Single Post Excerpt
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- have_posts() execution failure
- How to show a dynamic_sidebar if main content content’s height is > a set amount?
- Set WordPress Default Template
- How does the ternary operator work in the wordpress loop post?
- $wpdb->flush(); breaks the loop
- Adding hreflang tags automatically in WordPress subdirectory multisite
- Use object in template part
- Adding country tags automatically
- write custom woocommerce templates and forms
- Implement toggle switch for theme options in settings API
- Insert a button on a page with random number generation
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- Get first URL from post content
- Using a variable in is_page(array())
- Trigger popup in a php if/else statement
- Anyway to output the registration form like the login form with wp_login_form()?
- How do I get current page ID in WordPress customizer file?
- Can’t get page content in WordPress
- Customizer: Output default value in Customizer CSS
- How can I add multiple ‘tax_query’ arrays via a loop?
- Way to querry data (tags) from a wordpress database?
- How to load a template-part based on a url wildcard?
- ACF page while loop breaks footer while loop
- WordPress does not load page.php, return 404.php
- How to add values to media “whitelist_options” in wp-admin/options.php template?
- Global variable $post returning incorrect object
- How can I load a PHP page without using a Template?
- How can i upload images in an admin page?
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- Multiple WordPress Menus that will only display all pages
- Set the checkbox as checked by default at options page
- Using foreach loop breaks
- Cannot display or echo alt text on featured image