Support » Plugin: WP Club Manager - WordPress Sports Club Plugin » ‘Posts_per_page’ not working on custom WP_Query

  • Resolved glfoster

    (@glfoster)


    Hello,

    I have an issue with my WP_Query showing more than one post. Can you please inform me if it would have anything to do with your plugin code.

    I’ve researched and developed my code, and test multiple theories

    
    <?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; ?>
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not quite sure, but try this for your if statment:

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

    Thread Starter glfoster

    (@glfoster)

    Hello,

    thank you for responding. Unfortunately that hasn’t worked. I’m still working on a solution and once I have, I’ll post it here

    Plugin Author Leon

    (@leonterry)

    Hi,

    Sorry for the delay getting back to you!

    I can’t see anything wrong with your code and there isn’t anything with our code that should cause this. Have you found a solution yet? If not, I’m sure we can get to the bottom of it 🙂

    Cheers

    Plugin Author Leon

    (@leonterry)

    I’ve not heard back so I’ll mark this as resolved.

    Feel free to reopen if you still have questions 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘‘Posts_per_page’ not working on custom WP_Query’ is closed to new replies.