You can do this by using get_adjacent_post() and the filter get_previous_post_where or get_next_post_where. You’ll call get_adjacent_post() as normal, but you’ll need to change the LIMIT to 5, using the filter.
I wasn’t sure from the question whether or not you wanted to have the current post be first. If you do, you’ll need to set the LIMIT to 4 and then use the current postdata to generate the first post.
I would create an array of post ids, and then use get_post() when you iterate through them, as I believe that get_adjacent_post() will return raw rows from the database.
Related Posts:
- The correct method to pass query vars in AJAX using ajaxurl
- How to search display_name column when using WP_User_Query
- wpdb::prepare was called incorrectly
- How to order WP_User_Query results to match the order of an array of user IDs?
- Alter query on edit.php
- How to find objects by terms
- How to create a WP_Query to search the Title or Tag?
- How to order posts by modified date without using ‘query_posts’?
- How to get user by display_name with WP_User_Query
- Specific Loop For 2 Within Each
- WP database error for comments_popup_link()
- How to add a post or page tag to the list of classes appearing in the body tag’s class attribute?
- my function doesn’t return my post from today
- Display related products with custom output
- Get ID of child from child slug, while knowing parent ID
- List User order by ID in Descending order (Backend)
- How to get to a specific position in wp_query?
- Multiple choice in a custom taxonomy
- Get all user meta by meta key instead of ID
- Why is variable not working on custom sql query using wpdb?
- Get stock by custom meta field on all Woocommerce variable products
- Any possible way to make $wpdb->get_results() return anything else than array?
- Custom filter in admin edit custom post type responding with invalid post type?
- Echo a hierarchical list of post data from custom fields
- WP Query with custom Shortcode
- mysql query from wordpress page using custom table
- WordPress 3.2 query_posts and pagination, permalinks issue
- only show container with next/prev links if they exist?
- What query string parameter is available for index.php, that works for both pages and blog articles?
- Increase offset while looping
- Long running queries
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- How to pre populate a form field with a link of a current user’s author profile?
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Trying to get a PHP variable defined in a custom post into a javascript file. Null value. Using wp_localize_script
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- register_taxonomy() take much queries
- Which is the correct way to conditionally enqueue a CSS file?
- Odd / Even posts add class minus first post
- unable to use ‘new WP_Query’ in AJAX call
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- How to list commenters and days since last commented
- How to add div blocks after certain set of post
- Can’t update multiple rows with $wpdb query
- working with term_relationships table
- WordPress query undefined offset in loop
- Can I make get_users() query global?
- Issue with custom loop in Archive page
- How to display SQL query that ran in WC_Order_Query?
- Custom Post type slider with thumbnail navigation
- Parse error: syntax error, unexpected ‘}’ [closed]
- PHP -> SQL Query with Summing
- How to hide posts of a specific custom category in WordPress?
- WordPress PHP syntax doesn’t seem to be working correctly
- How to get thumbnail with pure PHP in a WordPress database?
- Why my query does not run with prepare
- mySQL queries are executed twice on wordpress website
- List of Events with Multiple Dates: Only NEXT Date
- Echo array value
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- Query pulling a single post per month
- WordPress Custom Query: Combining Two Functions
- SQL error with custom query
- WordPress Conditional / Multiple Taxonomy Query
- How can I modify this code to make the search box include tags and meta
- Reject all malicious URL requests functions.php
- Advanced Query posts
- How can I check that the acf field value is not a duplicate when adding a post?
- My Custom Post Type AJAX Query is Returning no posts – why?
- array wordpress when get is null
- Why does a header location on admin_head remove the query var I’m setting in the location?
- getting the values of hidden inputs to use them in a php mysql query
- Offset with ajax load more posts duplicates
- Let user select the number of posts shown per page jquery error
- Query doesn’t display text data with apostrophes
- How to query a staging database?
- How to make a parent page for author.php?
- Include a custom field in mysql query
- Echo multiple tasks if a common function exists
- How to enqueue assets only on queried pages, excluding the page being queried?
- “Where… like” query not working as expected
- Check if values exists DB
- Trying to exclude posts from a category on the home page
- Problems With Query and/or Template Part and/or PHP
- Arrange Category post manually when displayed
- The search engine of my website finds only posts and not pages, how can I solve this problem?
- Hide empty categories from get_categories
- Query Concatenation
- How to insert a variable into a query parameter?
- wp_query on search results page showing all results every time
- WP_Query not returning results
- Can WordPress support Website (19GB database) Should I move Our WordPress Website to a custom one using Laravel or any other PHP framework?
- Three different queries on same page
- Exclude a category ID from the following function
- Custom Filtering date with newsletter
- Pre_get_comments and orderby comment_karma
- taxonomy pages returning “NULL” when running default WordPress function ‘get_queried_object()’
- Hot to show custom post type taxonomies on archive page
- Display featured posts first, then display all others within a specific category in WordPress