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?
- WordPress Themes and PHP unit
- Any guides on creating custom admin pages?
- Customize default settings on new sites on multisite
- Dynamically change feature image in customiser
- Display only text to WordPress loop without loosing the text formatting
- Design view breaking on Pages
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- How do I translate this string – PHP syntax question
- Way to display “Yesterday”, “Today”
- using add_action for a header hook that has an additional parameter
- multiple if statements [closed]
- WordPress (3.9.1) MultiSite Permissions. Is chown the answer?
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- How to set variable, pass it to a partial file and remove it after?
- Can’t find infinite loop cause
- How to disable controls in theme customizer?
- WP_Query fails despite having 1 post
- Loop stopped working
- How to loop through all the attached images in a post, and get their url one by one
- Is There A Way To Make Theme Files Accept Shortcodes?
- WordPress import media error
- How do I display offsite database info on my wordpress site?
- Show recent posts starting at a specific number archive
- Hide Heading if ACF Field is empty
- Issue with custom loop in Archive page
- How to echo every parent page title?
- Getting posts to exclude from array
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- Custom post type permalinks do not appear using the link functions
- Using bloginfo and divs inside a php file
- WordPress call post-ID in jquery
- How to organize functions.php content
- Search page results conflicting logic – Search result caching?
- My worpress search page is showing no results
- How to extend SelectControl with data from my theme
- excep tonly one css, don’t load any css
- update_user_meta as multiple value but with same meta key
- add custom link to gallery images
- How to properly escape in ternary operators – Wp Coding Standards?
- Date of last blog update for specific authors only?
- PHP for loop not working as intended
- Rotating Header Images
- For each 3 posts, show a different post type
- Replace content in WordPress Page after GET from php page
- What is the best way to get the first few post from WordPress in different divs using a loop?
- Not able to call class in NHP framework
- Trying to put a search page on site
- Custom PHP-coding in MU installs
- WPMU – How to echo only one URL
- Loop on a wordpress Page instead of content coming from the WP text editor
- How to create a loop where loop changes every post?
- Create an if statement based on page_id
- hello can you advise how to fix the error?
- How to hide header and footer from page template
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Adding features to Gutenberg without theme.json
- The theme doesn’t load css and JS files doesn’t load in functions.php