Php Wordpress循环媒体;上载于;
我有一个网页,我想显示由某个作者上传的图像 在后端,如果我查看媒体,每个图像都有一个“上传人”属性,然后它会显示作者的姓名Php Wordpress循环媒体;上载于;,php,wordpress,loops,gallery,author,Php,Wordpress,Loops,Gallery,Author,我有一个网页,我想显示由某个作者上传的图像 在后端,如果我查看媒体,每个图像都有一个“上传人”属性,然后它会显示作者的姓名 (来源:) 我已尝试使用此循环: <?php // The Query $args = array( 'author' => $author_name_variable, // Replace with author id 'post_status' => 'any', 'post_type' => 'attachm
(来源:) 我已尝试使用此循环:
<?php
// The Query
$args = array(
'author' => $author_name_variable, // Replace with author id
'post_status' => 'any',
'post_type' => 'attachment'
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . the_content() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
这是一辆非常轻便的马车。有些作者会显示每一个媒体文件,其他人则没有;其余的都不准确。这是一个真正的盲目射击:/
我们的目标是循环浏览所有媒体文件,然后发布所有文件的内容(),并按名称上载相应的文件。如果有人能解释为什么在“作者”参数中ID比slug更可靠,我将不胜感激 我想出了一个解决办法。显然,“author”参数不喜欢用户名,所以我将其转换为ID,现在可以使用了。我使用了
get_user_by('slug',$username)
获取特定用户名的所有信息,然后将该数组分配给一个变量。然后,我过滤变量以仅使用ID,并通过参数传递该ID
以下是工作循环:
<?php
// The Query
$profileid = get_user_by( 'slug', $username );
$args = array(
'author' => $profileid->id, // Replace with author id
'post_status' => 'inheret',
'post_type' => 'attachment'
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . the_content() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
如果有人能在“author”一词中解释为什么ID比slug更可靠,我将不胜感激 我想出了一个解决办法。显然,“author”参数不喜欢用户名,所以我将其转换为ID,现在可以使用了。我使用了
get_user_by('slug',$username)
获取特定用户名的所有信息,然后将该数组分配给一个变量。然后,我过滤变量以仅使用ID,并通过参数传递该ID
以下是工作循环:
<?php
// The Query
$profileid = get_user_by( 'slug', $username );
$args = array(
'author' => $profileid->id, // Replace with author id
'post_status' => 'inheret',
'post_type' => 'attachment'
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . the_content() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>