我正在尝试使用以下代码从特定自定义帖子类型获取所有帖子:
$auctions = get_posts(array(\'post_type\' => \'auction\'));
print_r($auctions);
echo \'<select>\';
foreach ($auctions as $auction) {
    echo \'<option value="\' . $auction->ID . \'">\' . $auction->post_title . \'</option>\';
}
echo \'</select>\';
 虽然print\\u r()调用显示数据,但foreach似乎忽略了它,不打印任何内容。有什么想法吗?
任何帮助都将不胜感激
print\\u r()输出:
Array (
    [0] => WP_Post Object (
        [ID] => 36
        [post_author] => 1
        [post_date] =>    2013-05-19 10:58:45
        [post_date_gmt] => 2013-05-19 08:58:45
        [post_content] =>
        [post_title] => My Title
        [post_excerpt] =>
        [post_status] => publish
        [comment_status] => closed
        [ping_status] => closed
        [post_password] =>
        [post_name] => my-title
        [to_ping] =>
        [pinged] =>
        [post_modified] => 2013-05-24 09:55:53
        [post_modified_gmt] => 2013-05-24 07:55:53
        [post_content_filtered] =>
        [post_parent] => 0
        [guid] => http://domain.com/?post_type=auction&p=36
        [menu_order] => 0
        [post_type] => auction
        [post_mime_type] =>
        [comment_count] => 0
        [filter] => raw
    )   
) 
 
                SO网友:vagiag
                        \'post_type\' => \'auction\',
        \'posts_per_page\' => -1,
        \'post_status\' => \'publish\',
    );
$query = new WP_Query($args);
if ($query->have_posts() ) : 
    echo \'<select>\';
    while ( $query->have_posts() ) : $query->the_post();
            echo \'<option value="\' . get_the_ID() . \'">\' . get_the_title() . \'</option>\';
    endwhile;
    echo \'</select>\';
    wp_reset_postdata();
endif;
 @gregory实际上是对的,但有一些拼写错误。。。结束了
; 阵列中和末尾缺少
reset_postdata(); 必须成为
wp_reset_postdata();.现在应该可以了。。。这对我来说很好,没有任何问题!希望这会有所帮助!