You just set the ‘author’ parameter in a WP_Query
query or get_posts
(which accepts the same parameters):
$recent = get_posts(array(
'author'=>1,
'orderby'=>'date',
'order'=>'desc',
'numberposts'=>1
));
if( $recent ){
$title = get_the_title($recent[0]->ID);
}else{
//No published posts
}
(Note the ‘orderby’ and ‘order’ here are redundant because they are set to their default values, but you get the idea)
Related Posts:
- Get all image from single page using this query
- simple sql query on wp_postmeta very slow
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- wordpress query – orderby child post date
- Add multiple value to a query variable in WordPress
- Compare two numeric custom fields
- wp_dropdown_categories with multiple select
- How to tune search argument in WP_Query to show only exactly the same results?
- Custom query filter not working on woocommerce category page
- How to delete a transient on post/page publish?
- How to get my loop to pull posts into three columns
- Custom $wpdb Query for Custom Post Type by Category
- How to extract all ID variables from a query string?
- WordPress creating excessive joins on meta_query with search
- How to display liked posts of current user in wordpress?
- Remove Unnecessary Mysql Query
- Grouping related postmeta data via SQL query
- How to remove duplicate query on page load or make them cacheable
- Slow meta_query with about 4 milion record on wp_postmeta
- wpdb::prepare() isn’t working
- How can I apply a meta query for a single custom post type in the main query?
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- mySQL query. ORDER BY meta_key
- Disable the MySQL query in the main query
- Huge amount of queries on my site
- Strange string in console from wpdb query
- Using pre_get_posts to target a query in the sidebar
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- Select query for a login
- What’s wrong with my $wpdb prepare?
- How do I use get_query_var() within plguin code
- How to display related posts by same publish date?
- where should I reset query after using get_results?
- Get post according to current taxonomy
- Ordering by a metadata subfield in WordPress?
- Alter query with posts_clauses to retrieve NULL values last
- Query based on title, with ‘compare’ => ‘IN’
- wpdb print all post meta
- Issue with using add_rewrite_rule() for post querying custom fields
- Export Specific User data without plugin
- Plugin will sort users by usermeta
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Query posts according to specific post meta values
- wpdb COALESCE won’t work
- empty query breaks other queries
- Problem in exploding the_content to array
- Custom SQL Query passing array to WHERE p.id
- Query does not return content
- What is wrong with my wp query, cant exclude the category that i want
- how to insert missing tags into the posts through mySQL?
- Query posts dynamic date range
- Parse query filter in wordpress and relation
- How to write update query in WordPress to expire transients
- Query Nickname rather than Display Name in custom Woocommerce plugin
- Get previous posts list
- how to replace old DW site with new WP site? [closed]
- WordPress SQL query to tag all posts containing a specific word on title
- get_post_meta with WP_query
- Order terms by count – missing terms
- Querying Advanced Custom Fields
- How to rearrange a pool of posts joined using two queries?
- wpdb update multiple row?
- List WordPress Post and Related Attachments outside of a post page
- Can I include get_posts in this array?
- Custom query Custom-Post-Types creates error
- Formatting a date/time returned from a custom $wpdb query
- Problem on displaying the results on my query
- Rewrite rule for query params
- Improve performance of slow query
- WordPress search in modified post title
- meta_query not working
- Hook into the Admin Dashboard and redirect users
- WordPress query: merge meta key (number) values and sort
- Displaying data from custom table
- SEO friendly query vars
- Prevent versioning for .woff (font) files
- Orderby event date (if it exists) or post date (if it doesn’t) – how to reorder posts based on meta value OR date
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- OR condition not working
- Query not returning child posts for any parent post ID
- Limiting a filtered query
- Use $wpdb->get_results with filter based on array
- Add Hook for clearing transient when post is added
- Archive query not working correctly
- Custom MySQL Query for Post and Post Meta
- Displaying popular posts
- How to have more post in a page than in your home page
- Find all posts via SQL beginning with A of type B
- Show links to child pages on both parent AND child pages
- Access Tables with number prefix
- Modify Global Posts Plugin
- How to reference same column name but different table in custom db query
- Retrieving custom field array value through db query
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- How to add multiple values with add_query_arg?
- Query parsing only author ids
- 3 queries to update WordPress
- How to figure out correct wp_options to have autoload=’yes’