Results not being printed

时间:2014-01-31 作者:localhost

我正在尝试运行以下代码,这是我从site 但我没有看到任何输出。当我这样做的时候print_r($product) 只有这样我才能找回阵列。

$args = array(  
    \'post_type\' => \'product\',   
    \'posts_per_page\' => 4  
);  
$featured_query = new WP_Query( $args );      
if ($featured_query->have_posts()) :   
    while ($featured_query->have_posts()) :   
        $featured_query->the_post();  
        $product = get_product( $featured_query->post->ID );  
        echo $product;
    endwhile;     
endif;  

1 个回复
最合适的回答,由SO网友:tfrommen 整理而成

你是_doing_it_wrong, 像$product 是一个对象。

我很确定你想要这样的东西:

$args = array(
    \'post_type\' => \'product\',
    \'posts_per_page\' => 4,
);
$featured_query = new WP_Query($args);

if ($featured_query->have_posts()) {
    while ($featured_query->have_posts()) {
        $featured_query->the_post();
        ?>
        <h1 class="post-title"><?php the_title(); ?></h1>
        <div class="post-content"><?php the_content(); ?></div>
        <?php
    }
    wp_reset_postdata();
}

结束

相关推荐