global $wpdb, $post; // Uses current POST here
$IDs = $wpdb->get_col("SELECT `ID` FROM {$wpdb->posts}
WHERE `post_type`='{$post->post_type}' AND `post_status`='publish' AND `ID`<{$post->ID}
ORDER BY `ID` DESC LIMIT 5;");
This function lists the 5 posts with IDs lower then ID 176
that are of post_type="post"
and post_status="publish"
. Change post_type if you use a custom post type to whatever you need. You can also order by post_date_gmt
if you want.
Regards.
Related Posts:
- Determine if page is the Posts Page
- How to get ‘post_content’ without stripping tags?
- Post preview mechanism architecture
- Post featured image column on admin post list page
- display all posts in wordpress admin
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- When and Where is `global $post` Set and Available?
- Counting words in a post
- Create an “All Posts” or “Archives” Page with WordPress 3.0?
- How to programmatically create posts in wordpress?
- How to Sort Custom columns in admin
- Shortcode Not displayed at the Right Place [duplicate]
- Post visibility on the basis of roles
- List only child categories a post is in, of a specific parent category
- Unattaching images from a post
- is there a better way of combining this?
- How to change post status from publish to draft using hook in wordpress?
- How to output comments number of a post per day?
- get_permalink executes link without https
- Auto Refresh Post List after X seconds
- How to show video from specific category on sidebar?
- Display posts with comments closed, with pagination?
- How can I add a meta-box to the posts editor containing all items of a custom taxonomy as checkbox?
- can’t use the page_test method to check pagination
- post re-order on my site
- WordPress blog post cloned and stolen?
- What is the Better way to manage posts in WordPress?
- Allow multiple contributors to one post
- How to check a post exist when the permalink has post id in it?
- wp-cli post create & media import issues
- Getting the current author (it has changed) of a post, not the original author
- Post body text occupying featured image space before it loads
- User levels and post visibility
- Multi row post list
- Hook in to add new post link wp admin?
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Dynamically switch template on click
- How show categories in admin and get that selected to show posts in index
- Get posts with multiple categories
- Do not show children of a category
- Tell WP to use a specific template file in posts
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- How to get post content from an array of ids?
- Hide custom metabox value from custom fields
- See if a post has a specified tag
- Where exactly should I hook in order to change the post’s ID before insertion in the database?
- Images showing up in Post Editor, but not in Published Post
- Custom wp-query in wordpress rest api
- WordPress pagination and Post Navigation not working on home page
- Custom Fields for Author Box
- Custom home page with full post for first one only
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- Load widget only on blog posts
- Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
- Change the background of each post according to the category
- Issue with first top post display order
- Let Posts be stored in another table
- List latest posts with least comments in WP-Admin
- Widget to show posts in the sidebar basing on its IDs
- How to view all posts (on site, not admin) that are uncategorized?
- How to create a list of links to post with specific category
- Page of posts made to look like homepage
- get parent fields title, content excerpt etc
- Changing permalink of WordPress
- Rest API Paginate until all posts are imported
- How to show multiple posts thumbnail, title and date in widget
- Remove all external links from posts
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- Query to fetch custom taxonomy along with post title
- exclude particular category in api
- Change of author not updating
- Make categories appear random
- Single post shows post three times
- How to find the edit link of the WordPress Post from the URL
- Blog Page doesn’t show summary but full content
- Change WordPress names duplicate titles (url)
- Get posts from category from custom query
- Changing a users posts to drafts upon role change
- Show 5 posts and than 3 posts offset with pagination
- My posts page is missing the page title
- Alternative content between posts no repetition
- Start loop from specific post ID
- Connection dropped due to file size
- How to Get Position of a Post from a category and tag
- Custom author search
- WordPress template next_prev
- My blog “page” used to show a list of posts, but now it’s just showing the page content?
- Grab next post title in archive page
- Displaying categories items among posts
- unused post IDs
- Combining multiple conditional statements [closed]
- First post in loop displays twice
- custom post type single page template not working
- Is there a block to print post link standalone in a block theme?
- Export Posts Without Categories In An XML File
- How to show video from post on the all posts page?
- Show a page counter for pagination