如何在WordPress中显示5条随机帖子?我的循环无法正常工作吗?

在添加查询以进一步自定义循环之前, 该循环运行良好。我究竟做错了什么?

我试过添加wp_reset_postdata();在收盘之前结束, 而&结束则无济于事。除非我没有其他问题?

    <?php
    $args = array(
        'orderby'        => 'rand', 'posts_per_page' => '5', );
    $my_query = new WP_Query( $args );
    if ( $my_query->have_posts() ) {
        while ( $my_query->have_posts() ) {
            $my_query->the_post();

            get_template_part( 'template-parts/content/entry_cards', get_post_type() );

        } // end while
    } // end if

    ?>

我希望能够以随机顺序查看5个WordPress帖子(如数组中所述)。


#1


我相信:

$args = array(
    'orderby'        => 'rand', 'posts_per_page' => '5', );

应该:

$args = array(
    'post_type'      => 'post', 'orderby'        => 'rand', 'posts_per_page' => '5', );

WP_Query()需要知道要提取哪种数据。

来源:

https://www.srcmini02.com/63249.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37659.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?