The following query retrieves the oldest post of a specified user/author:
$user_id = 42; // or whatever it is
$args = array(
'posts_per_page' => 1,
'post_status' => 'publish',
'author' => $user_id,
'orderby' => 'date',
'order' => 'ASC',
);
$first_post = new WP_Query($args);
if ($first_post->have_posts()) {
$first_post->the_post();
// Now you can use `the_title();` etc.
wp_reset_postdata();
}
If you want to show the first post a specific user wrote (no matter what the post’s publish date is set/altered to), then you have to use 'orderby' => 'ID',
.
Related Posts:
- Is it possible to Schedule Attachments in WordPress?
- Query posts from current year
- featuring old articles without messing up with the archive
- Post: how to set created date after post has been published [closed]
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Bulk Post update_post_meta
- Query post for today, if no post get the previous one
- Get page ID of page that is set as the posts page
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- How to get posts published between a date and today?
- How to get post creation date?
- add action only on post publish – not update
- Changing the post date and time with function
- How to prevent posts from being published too close to each other?
- Are post ID’s reliable?
- Get current post id in functions.php
- Random sort within an already sorted query
- get all posts ID from a category
- how to get a different html for odd/even posts?
- Elegant way to include only published posts with get_objects_in_term()?
- using wp_update_post on save_post
- Get the current post ID as a variable in Javascript
- Is post ID number always incremental n+
- WordPress plugin to publish to multiple remote WordPress blogs
- Post publish only hook?
- Publish pending article from front end with a button?
- How to add a “publish” link to the quick actions
- How to put last edited entry on top of the blog-post list?
- How to limit user to publish post per day and per role?
- How to know if get_posts() failed?
- Using $wpdb to query posts with meta value containing current post_id
- When a user creates a post (pending), send a confirmation link that allows them to publish
- In what sequence are the hooks fired when a post is “published”?
- Restrict the Number of Posts an Author can Publish (over time)?
- WordPress Number of Posts Not Changing With posts_per_page
- Add javascript when post is published
- Are all ID’s used unique?
- Update existing post dates to random dates
- I have over 4000 posts, will querying some of them cause performance issues?
- Duplicate posts
- Looping through posts per category gives same posts for each category
- How to show posts rank based on custom field value
- $post->ID displays wrong ID
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- How do I create Comma Separated list of attached image ids?
- How to add posts to wp_query result?
- Publish posts only after the condition is met
- Trying to put an array into ‘post__in’ => array() query not working
- Hiding by default specific post status on backend list?
- How to display an icon when a new post is published and then remove it when a specific time past?
- How to output comments number of a post per day?
- Human Time Diff, change mins to minutes
- Order post by year DESC and month ASC
- Showing random content / pictures from earlier posts in a sticky post?
- Display custom post types by date field
- Detect Post Type when publish_post is ran
- Get the post_id of a new post
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- get post id in while loops outputting page id
- Does WordPress remove draft status automatically?
- Undefined variable post_id in custom quick edit coloumn
- Query All users that has post
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- Prevent post from being published if no category selected
- Send email to user that his post has been rejected
- wp_enqueue_media() slows down my WP site
- Can wordpress differentiate between added and updated posts?
- Fetch posts from current week (Sunday to Saturday)
- Limit number of posts a user can make per minute?
- How can I get all posts data from within a paginated search result?
- Search query – exact post title match
- Every possible way to get data (posts) from WordPress
- publish_post conflicts with save_post
- Sorting posts alphabetical that have single digits
- Query posts from different categories in multisite
- How to set post expiration date and time and move the page to archive after expiration [closed]
- Check if post exists
- posts_per_page doesnt work
- Sorting posts according to view counts not working
- Getting post id from wp_insert_post_data function?
- Does an article (post) id ever change?
- Display page content AFTER a loop of posts
- Notification to Admin or Author upon new post [duplicate]
- How to get the post’s parent ID?
- Can a page_id and a post_id be same?
- Only display posts after current date
- Get posts by multiple ID’s (query)
- What differences are there between a Privately Published post and a Draft post?
- How to start with post number x?
- How to run a function when post is edited or updated using publish post action?
- How can I create custom button in post.php
- Exclude posts with empty post_content in wp_query
- Only display a certain number of posts, dependent on how many posts there are available in a query
- Is there a better, more efficient way to get the post id outside the loop?
- Getting current post ID in functions.php
- Improving WP_Query for performance when random posts are ordered
- Buddypress activity id
- How to rename “Publish” metabox title in post screen
- Display post from specific date