本例循环浏览所有摄影师,然后显示他们上传的所有图像:
<ul>
<?php
$photographers = get_users( \'role=photographer\' );
foreach( $photographers as $user ) :
$pictures = new WP_Query( array( \'author\' => $user->ID, \'post_type\' => \'attachment\', \'post_status\' => \'inheret\', \'posts_per_page\' => -1 ) );
echo \'<li><h3>\' . $user->user_nicename . \'</h3>\';
if ( $pictures->posts ) :
echo \'<ul>\';
foreach ( $pictures->posts as $picture ) :
echo \'<li>\'. wp_get_attachment_image( $picture->ID ) .\'</li>\';
endforeach;
echo \'</ul>\';
endif;
echo \'</li>\';
endforeach;
?>
</ul>
它使用
get_users 函数可获取分配了摄影师角色的所有用户。下一个a
new query 基于获取所有附件的每个摄影师ID生成。