Depending on context, you may need global $post;
first, so you’re not operating on a different local var. You also already have a post object, so you could just assign that directly to $post
before calling setup_postdata
…
However, you can skip all that and use functions that accept a post object argument-
$prevPost = get_previous_post(true);
if($prevPost) {
echo get_permalink($prevPost);
echo get_the_post_thumbnail($prevPost, 'thumbnail');
}
Most of the template functions have alternates that work this way.
Related Posts:
- Get Next / Prev 3 Posts in Relation to Current Post
- Add title for previous and next posts to Yoko Theme
- WordPress The Next Posts
- get next/previous post name
- How to get post creation date?
- Add tag to post api wordpress
- Confirmation box when submitting post for review
- How to show list of posts by author and category?
- how to limit and display tag?
- Insert custom div between posts
- How to Display Post View Count
- Remove double space after a period
- Adding Multiple Values to a Post Meta Key
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- display order of connections
- Warning: Creating default object from empty value in … /post.php
- Conditional that checks if a current category has any subcategory with posts
- Display page content AFTER a loop of posts
- How to get the date of a post in WordPress, so I could use it in a script?
- Unwanted Duplicate Posts Showing in Pagination Pages
- Is there a better, more efficient way to get the post id outside the loop?
- How To Add One Tag to Multiple Posts?
- how to find user ids of all commenters in a post
- Automatic post deletion
- Lose “Blog Archive” from page title
- Should a photo gallery be in a post or on a page?
- Automatically Updating Publish Date Bug
- Properly display posts on homepage
- Add custom Facebook share link with share count and variable text
- How can I show many posts an author has per week?
- Disable inline_edit() on edit.php
- Display post X of Y in category
- I can’t format text in th edit page (or posts) whats wrong..?
- “more” tag doesn’t appear when browsing category achives or search
- How to exclude latest x posts from a paginated query?
- Auto Filling Post fields
- Help with Taxonomies
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- WordPress Sidebar menu for posts based on date – guidance needed
- Users problem (multi-author plus multisite)
- Filter only the text in the_content
- How to WP_Query() from multiple blogs and order them?
- Update Post Meta is adding a value to my serialize array
- Is it possible to filter the main loop to exclude posts from a specific category?
- Hide a specific post from a page template
- Posts – display all posts except a post by an ID
- Subdomain to website directory blog transferring
- Display author’s name and avatar in post’s sidebar
- How do you change the comment count in the back end posts list, to reflect unapproved comments, rather than all comments?
- How to change the layout of posts when viewing all posts by tag [closed]
- Intercept page request and add value to it
- Parent category / child category posts
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- HTML Form Submit to table in same page
- Call current post URL in ajax
- How to check if a post is published today?
- Detecting current page from class method
- How can I add a class to particular paragraphs in my post?
- How to select particular month post from table and update the post status using MySQL?
- Exists filter or action that change Add New Post link?
- saving/reading custom field value does not work – no value gets POSTed
- Getting an extra post’s meta data?
- Have posts included on a page that share same category
- displaying the categories post
- Preview page/post revisions without overwriting current content
- Adding external field to my post form (admin side) and to post show (frontend side)
- fetching posts and showing on frontpage
- Insert JavaScript in a blog post or a new page?
- How to create loop of posts except post ID defined via ACF field
- How to pull sticky post permalink inside php?
- Add CSS and JS files of the template post on a WordPress page
- New Post bubble
- show only one category and filter by tag
- How to redirect if is post edit or publish page?
- How to delete/customize imported demo content from a theme or add my own?
- How can I exclude only a specific sub category post from category display?
- testing result of $.post with json_encode
- Clean up customize_changeset in DB
- Update user meta when post published no working
- Posts are not showing up on next page.
- count_posts to a standalone link
- Post as frontpage – avoid duplicate content
- Blog styling in SASS
- Is there a way to change the complete URL of the blog post for a redirecting tracking link?
- WordPress with static posts page and custom permalink structure doesn’t find posts with numeric permalinks
- My posts section for logged in user
- Preview own posts if logged in
- Pagination for custom query won’t let me back on page 1
- Latest posts on all pages
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- Permalink remain the same on each page
- Displaying warning if no featured image has been set – Post Editor
- How to highlight most recent posts in a list
- wordpress show category link instead of post link [closed]
- CSS – Change height of Storefront / WooCommerce product categories, but not products
- How to add a new page that will function as a separate blog/news article page
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Show Next/Previous without Link
- Filters do not work when there are multiple (one works)
- WordPress Ajax load doesn’t work