Wordpress - Get latest custom post from every user -
how can latest custom post every user?
$args = array( 'post_type' => 'userdatax', 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'desc', 'posts_per_page' => 999999 ); $query_res = new wp_query($args);
according me below code can achieve goal.
try code
function getuserposts() { $args = array( 'order' => 'asc', ); $users = get_users( $args ); foreach ($users $key => $value) { // wp_query arguments $args = array( 'post_type' => array( 'userdatax' ), 'post_status' => array( 'publish' ), 'author' => $value->id, 'posts_per_page' => '-1', 'order' => 'desc', 'orderby' => 'date', ); // query $query = new wp_query( $args ); // loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // echo the_title(); } } else { // no posts found } // restore original post data wp_reset_postdata(); } } add_action('init','getuserposts');
Comments
Post a Comment