WordPress查询仅返回1个结果,但所有结果均为nonpaging = true

时间:2019-02-27 19:26:34

标签: wordpress

完全与此混淆。

如果我将nonpaging => true添加到查询中,则会得到所有结果。但是,我希望在此特定循环中仅显示4。如果我使用post_per_page => 4,我只会得到一个。

更糟糕的是,如果我在orderby中添加=>'rand',我会得到1-5之间的一些数字。

到底是怎么回事?!?!?

// WP_Query arguments
    $args = array (
        'post_type'              => array( 'bottin' ),
        'posts_per_page'         => 4,
    );

// The Query
    $bottin = new WP_Query( $args );

// The Loop
    if ( $bottin->have_posts() ) {
        while ( $bottin->have_posts() ) {
            $bottin->the_post();

            $voir_plus = get_field('voir_plus');

        if ( !empty($voir_plus) ) {

            // Vars
            $link = get_the_permalink();
            $image_url = get_the_post_thumbnail_url();
            $name = get_the_title();
            $posttags = get_the_tags();

            echo '<a href="' . $link . '"><div class="elementor-row"><div class="elementor-col-50"><img src="' . $image_url . '" class="img-responsive" width="300"></div><div class="elementor-col-50 intervenant-info"><h6>' . $name . '</h6><p>';
            if ($posttags) {
              foreach($posttags as $tag) {
                echo $tag->name . ' '; 
              }
            }
            echo '</p></div></div></a>';
        }
    }
} else {
    // no posts found
}

1 个答案:

答案 0 :(得分:0)

我认为您需要“分页”,您可能需要检查一下https://codex.wordpress.org/Pagination

public DataView Updateinfo()
    {
        conn.Open();
        MySqlCommand command = conn.CreateCommand();
        command.CommandText = "UPDATE partijen SET fvzitter='vzitter2', info='info2', zetels='zetels2', stroming='stroming2' WHERE partij='partij'";
        MySqlDataReader reader = command.ExecuteReader();
        DataTable dtData = new DataTable();
        dtData.Load(reader);
        conn.Close();
        return dtData.DefaultView;
    }   
相关问题