I’m thinking you are just missing a wp_reset_postdata()
call after you foreach loop. Take a look at get_posts()
, which is used by wp_get_recent_posts()
, to see an example usage.
Besides that you do not need the if (have_posts())
and the_post();
in your widget code. But should make use of setup_postdata()
.
Edit:
Example:
$argum = array(
'numberposts' => $naujienu_sk
);
$recent_posts = wp_get_recent_posts( $argum );
foreach ( $recent_posts as $post ) {
setup_postdata( $post );
// code
}
wp_reset_postdata();
Related Posts:
- Custom text box containing post titles
- Display recent posts with thumbnail within Masonry
- How do I use wp_get_recent_posts?
- Add Date to Recent Posts Widget?
- Recent Posts widget has some older posts at the top? [closed]
- how to show post content with post name in sidebar?
- Adding a badge to new blog post titles
- Display recent post by tag
- Small intro before latest blog posts
- WordPress Recent post only showing title
- Recent post on single page from specyfic category
- How to display posts on template
- Help with “Recent Posts” Loop that is specific to a topic
- Get Each user recent post in wordpress
- Code for Recent Posts Widget
- Modify recent post sidebar to show post thumbs with out plugins
- Display all comments or recent comments per user on author page
- Add inline HTML to posts published within last 24hrs
- Add thumbnail to recent posts widget using filters
- How to exclude categories from recent posts, recent comments & category widgets?
- meta_query not working properly
- Unable to show recent custom post types in default recent posts widget
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Show recent published posts
- If numberposts = -1 offset won’t work
- How to display recent posts added in several custom post types
- Order posts by meta value and Date
- What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?
- How can I show recent posts from same taxonomy as the post currently being viewed?
- How to display recent / random posts by its category
- Grabbing specific content
- Recent Posts widget without Title
- Change recent posts widget title
- How to start with post number x?
- Create static front-page with 3-5 recent posts
- Display most recent post on homepage?
- How to truncate titles in Recent Posts widget?
- Customizing wordpress default widgets?
- Recent posts with featured image or fallback image with permalink
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- How do I add recent posts to the menu?
- WP Bakery Load More Button loads the same posts
- menu item to display the most recent post
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- Custom recent-posts shortcode’s thumbnail image not in line with rest of code
- How to get date of post when using wp_get_recent_posts()?
- Proper way to display latest 5 posts grouped by post type?
- Reset WordPress Post Query to default
- Author list based on recently active
- How to get excerpt of the recent posts
- List most recently added posts (with a twist)
- Recent posts on homepage
- How to obtain the recent posts without their content in an efficient way?
- How to check if the current page is at a specified path in the URL?
- Posts modified in the last 48 hours
- How to avoid duplicates when creating recent network posts
- How to Link to Most Recent Custom Post of Same Term
- widget_posts_args not using the number of posts in widget
- Display css ONLY on most recent post of specific category?
- Sort / display recent posts by publish date
- Add hero image to home page (blog format) via the dashboard
- Exclude latest post from WP_Query taxonomy term loop
- Why aren’t paragraphs breaking on this page?
- Problem with Front-Page.php loading recent posts
- Showing recent post of category in page
- How to show 3 most recent/viewed posts in a special tiles on home page using wordpress?
- Where to add offset?
- Homepage custom recent news
- How to add a recent post function to a text widget I created for practice?
- showing all recent posts in theme
- How do I add a small excerpt of a blog post on my Front Page Recent Posts widget?
- Import Recent Posts Only and Ignore old ones if exist
- add title to widgets of wordpress
- Cannot manage to display my CPT in Recent Posts widget
- Display Most Recent Post Widget Title On Page
- The styles in the recent posts widgets plugin not working
- WordPress recent post
- Posts Per Page with a button to add more Posts
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- Showing wordpress latest post thumbnails in slider with auto increment
- Best way to add image to recent posts widget?
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- Recent Posts Widget URL / Domain change
- Recent post in the middle of the content
- Recent posts show thumbnail
- Paginate recent posts widget
- Show all posts of all categories but excluding a category on custom blog page with pagination of my theme
- Show recent posts in single-post page
- Duplicate content with the same URL, google authorship
- shortcode for recent custom type post
- Building Menus with the latest posts included
- Query recent posts by author
- Adjust layout most recent post, taking pagination into account
- Author Link in Recent Posts Widget
- how to show the most viewed, random and recent posts in the home?
- Lists Top Authors by Most Recent Posts
- How to display recent posts on home page with title, post date, author and featured image?
- Recent posts with different class name for each post and a scrollbar?
- Recent posts with comment count in “Sidebar” template [closed]
- How to display Most Recently Read 10 Posts by a logged in user in wordpress