I am trying to get the latest inserted post_id by an author using wp_query class. I have to use MAX(wp_posts.ID) in the args of the query i use. Is this somehow possible using wp_query class or do i have to use wpdb::get_results()? Any help appreciated.
-
I think this link will be helpful to you wordpress.stackexchange.com/questions/95004/… – Kanon Chowdhury Nov 26 '19 at 13:37
-
Thanks for your suggestion but i need to use MAX(wp_posts.ID) . I can not use orderby date. – stefanosn Nov 26 '19 at 13:42
try this
<?php
$new=new WP_Query(array('posts_per_page'=> 1,'order_by'=>'DESC'));
$max_id;
if($new->have_posts()){
while($new->have_posts())
{
$new->the_post();
$max_id=the_id();
}
}
echo $max_id;