theo tôi bên dưới mã có thể đạt được mục tiêu của bạn.
thử mã này
function getUserPosts()
{
$args = array(
'order' => 'ASC',
);
$users = get_users($args);
foreach ($users as $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',
);
// The Query
$query = new WP_Query($args);
// The Loop
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
// do something
echo the_title();
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();
}
}
add_action('init','getUserPosts');
Nguồn
2017-09-14 11:20:39
mẫu mã đẹp. Hmmm, dường như không hiển thị bất kỳ nỗ lực nào thực sự do người dùng truy vấn .... bạn có thể cụ thể, _every user_ không? –
bạn đã thử đặt posts_per_page thành -1 chưa? –
Bạn có muốn hiển thị bài đăng mới nhất từ người dùng thông minh hoặc đăng nhập người dùng hiện tại không? – purvik7373