Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义WP#u查询';每页张贴';它不起作用了_Php_Wordpress - Fatal编程技术网

Php 自定义WP#u查询';每页张贴';它不起作用了

Php 自定义WP#u查询';每页张贴';它不起作用了,php,wordpress,Php,Wordpress,当我声明“每页发布”时,我在显示多个帖子时遇到问题 在我的研究过程中,我的代码已经开发出来了,但仍然没有结果。我试过了 'ignore\u sticky\u posts'=>1,'nopage'=>true(分页) 切换主题和停用插件。我似乎找不到问题所在。任何帮助都将不胜感激。以下是当前的结果- 我在页面上有两个循环,这是一个自定义页面模板。我在用电话 下一场比赛在 也许您的下一个循环从上一个循环获取查询。 确保您使用的是查询帖子和/或wp\U查询 在每个循环之后。如果两个循环的数据被覆盖,

当我声明“每页发布”时,我在显示多个帖子时遇到问题

在我的研究过程中,我的代码已经开发出来了,但仍然没有结果。我试过了

'ignore\u sticky\u posts'=>1
'nopage'=>true
(分页)

切换主题和停用插件。我似乎找不到问题所在。任何帮助都将不胜感激。以下是当前的结果-

我在页面上有两个循环,这是一个自定义页面模板。我在用电话


下一场比赛在

也许您的下一个循环从上一个循环获取查询。 确保您使用的是查询帖子和/或wp\U查询


在每个循环之后。

如果两个循环的数据被覆盖,那么您的第一个代码wp\u reset\u query()不正确。如果您使用的是WP_查询,那么

wp_reset_postdata() //remove wp_reset_query() which is used for wp_query()
应该在WHILE循环结束后使用,这意味着在两个循环中必须

wp_reset_postdata()  // use this at both loops
在while循环末尾的两个循环中

现在您看到的代码如下所示:

<?php 

 $wpb_next_game = array('post_type'=>'wpcm_match', 'post_status' => 'future', 's' => 'Alderney', 'posts_per_page' => 1 );

 $wpb_next_game = new WP_Query($wpb_next_game);
  if ( have_posts() ) : while ( $wpb_next_game->have_posts() ) : $wpb_next_game->the_post();

         $date = date_i18n( get_option( 'date_format' ), strtotime( $post->post_date ) );
         $time = date_i18n( get_option( 'time_format' ), strtotime( $post->post_date ) );
         $side = wpcm_get_match_clubs( $post->ID );

         // badge
         $badges = wpcm_get_match_badges( $post->ID, 'crest-medium', array( 'class' => 'home-logo' ) );
         $badges = wpcm_get_match_badges( $post->ID, 'crest-medium', array( 'class' => 'away-logo' ) );
         $format = get_match_title_format();
         if( $format == '%home% vs %away%') {
            $badge = $badges[0];
         } else {
            $badge = $badges[1];
         } 
         ?>

    <div id="next-match" class="row">
     <div class="span_6 col">
        <h3 class="next-match-home"><?php echo $side[0]; ?></h3>
     </div>
     <div class="span_6 col">
        <h3 class="next-match-away"><?php echo $side[1]; ?></h3>
     </div>
  </div>
     <div class="row">
        <h4 id="next-match-time">Next Match at <?php echo $time; ?> on <?php echo $date; ?></h4>
     <?php endwhile; 
     wp_reset_postdata();
        ?>
     <!-- end of the loop -->
 <?php else : ?>
    <h4 id="next-match-time"><?php _e( 'Sorry, scheduled matches' ); ?></h4>
 <?php endif; ?>

下一场比赛在
希望这对你有用


谢谢你

谢谢你的回答。不幸的是,它没有解决这个问题。然而,由于您的代码是正确的,我相信这是一个主题问题。我的搜寻还在继续,但我离找到答案又近了一步。我使用的主题是“Sailent”,他们仍然在使用分页参数
'showposts'
,自wordpress 2.1版以来,它已被
'posts\u per\u page'
取代
<?php 

 $wpb_next_game = array('post_type'=>'wpcm_match', 'post_status' => 'future', 's' => 'Alderney', 'posts_per_page' => 1 );

 $wpb_next_game = new WP_Query($wpb_next_game);
  if ( have_posts() ) : while ( $wpb_next_game->have_posts() ) : $wpb_next_game->the_post();

         $date = date_i18n( get_option( 'date_format' ), strtotime( $post->post_date ) );
         $time = date_i18n( get_option( 'time_format' ), strtotime( $post->post_date ) );
         $side = wpcm_get_match_clubs( $post->ID );

         // badge
         $badges = wpcm_get_match_badges( $post->ID, 'crest-medium', array( 'class' => 'home-logo' ) );
         $badges = wpcm_get_match_badges( $post->ID, 'crest-medium', array( 'class' => 'away-logo' ) );
         $format = get_match_title_format();
         if( $format == '%home% vs %away%') {
            $badge = $badges[0];
         } else {
            $badge = $badges[1];
         } 
         ?>

    <div id="next-match" class="row">
     <div class="span_6 col">
        <h3 class="next-match-home"><?php echo $side[0]; ?></h3>
     </div>
     <div class="span_6 col">
        <h3 class="next-match-away"><?php echo $side[1]; ?></h3>
     </div>
  </div>
     <div class="row">
        <h4 id="next-match-time">Next Match at <?php echo $time; ?> on <?php echo $date; ?></h4>
     <?php endwhile; 
     wp_reset_postdata();
        ?>
     <!-- end of the loop -->
 <?php else : ?>
    <h4 id="next-match-time"><?php _e( 'Sorry, scheduled matches' ); ?></h4>
 <?php endif; ?>