有没有办法通过用户获取附件?我需要一种方式来显示特定用户上传的所有图像。(我可能需要附件ID以便使用wp_get_attachment_url
以显示它们。)
Get attachments by user
1 个回复
最合适的回答,由SO网友:Rob Vermeer 整理而成
$user_id = 1;
$the_query = new WP_Query( array( \'post_type\' => \'attachment\', \'post_status\' => \'inherit\', \'author\' => $user_id) );
if ( $the_query->have_posts() ) while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
这将显示用户id为1的用户的所有附件标题。您可以使用get_the_ID()
在循环中获取附件ID。结束