The problem is that wp_reset_postdata
attempts to restore $post
from the main $wp_query
, but on post.php
in admin, $post
isn’t populated from $wp_query
, so wp_reset_postdata
fails to restore it. The solution is to use get_posts
and a foreach
instead of WP_Query
and the loop.
Related Posts:
- How to detect single.php (but not single-portfolio.php)?
- Function to execute when a post is moved to trash .
- Changing the post date and time with function
- Get current post id in functions.php
- Dynamically add id to heading tags
- disable WP automatically inserted line breaks after an image
- Getting the post_id in wp_ajax function
- Fatal error: Call to undefined function post_exists()
- How to publish a post with empty title and empty content?
- delete post also attachments
- How to call function within a page/post, to dynamically generate content?
- Restrict users from editing post based on the age of the post
- How do I use element instead of tags in WordPress post content having webP support?
- Keep a fluid max number of posts on site
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- How to add an admin function only to posts, not pages?
- Human Time Diff, change mins to minutes
- How to get new post URL?
- Force update all posts in custom post type, no content changes
- Disable REST API for a user ROLE
- How to Display Post View Count
- Remove double space after a period
- Add confirmation popup on “Move to Trash”
- $post object is null
- How to change the page break URL from ../post/2 to …/post/page2/
- How can I list random authors from current post category?
- Disable single post page
- Enabling post thumbnails for custom post type
- Run a function when post is deleted?
- Getting current post ID in functions.php
- Add icon/badge next to posttitle of specific category
- Prepend or add an Image to the content of a Post
- Load post attached images on a single page site with fancybox
- Exclude category from
- Setting posts_per_page for taxonomy term template
- Change post order random through out the entire WordPress
- How to display the link (title) and thumbnail post?
- How to do set post permalinks using 6 digit random unique function?
- Can’t get buddypress notifications in front-end; why do I get this error?
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Send post id through ajax and get the post content back
- Force authors to Preview a post before publishing
- Change all author links in Blog roll
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Every second post different class in blog view
- Format latest/newest post differently
- is_page Funtion for Posts ?
- Get post meta retrieving wrong value
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Isn’t the way posts are displayed very unefficient?
- Add custom text automatically on each post
- restrict incrementation of post vies count when refreshing the page
- Using system date format
- Get post by tag
- Related Posts function not working
- the_content() Not Grabbing All Content
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- saving/reading custom field value does not work – no value gets POSTed
- Same post appears in related Posts?
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Have h2 tag not show up if there are no blog posts
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Help on conditional statement to accompany wp_insert_post function please?
- How to implement a WordPress comments function?
- How to add content above footer in posts from specific category
- get category in list of posts // shortcode for custom related posts
- shortcode // get posts by ids
- Find most used words in post titles
- $post->post_content empty while all other properties are correct
- Replace Tag Keyword With Link Within Post Content
- AJAX load more posts not using correct category and repeating the same few posts
- Get post id outside loop : Notice: Trying to get property of non-object
- How to correctly escape data
- Display author bio box
- Check if user has avatar
- im trying make a function to auto correct posts when i open the posts in the backoffice
- How to change number of posts shown on homepage vs other pages?
- Show only top 3 posts from 3 categories in order on home page
- Run function after post is updated
- How to get posts from network blog
- When Author add new post change default status to pending
- fire action when post is being edited as well as saved?
- Get post title by Alphabet
- How can I create a menu items from meta box based on users input
- Getting rid of the blog page entirely
- How to use wp_editor(); in functions.php then retrieve content in the template
- List direct children of page
- How *not* to show the last post on the latest posts list
- save_post not working
- Display a custom field rating system in the front end
- wp trim function not working
- Insert Shortcode exactly at the end of the content
- Ajax calls in wordpress
- display last post modified date in genesis child themes
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Show Next/Previous without Link
- Filters do not work when there are multiple (one works)
- How to use shortcode to get the second to newest post?