WordPress中的新手参考我的下面的编码,它没有得到所有记录:
post_author ='1' and post_type ='attachment'
它只是返回单行。在我的数据库有20行,其中:
post_author ='1' and post_type ='attachment'
这是我的PHP代码:
<?php
$args = array('author' => '1' ,'post_type' => 'attachment');
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
// now $query->post is WP_Post Object, use:
echo $query->post->ID;
}
}
?>
答案 0 :(得分:0)
尝试以下代码
使用docs
$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;