i am new to wordpress, here, what i am doing is fetching the thumbnails of post type= organisation,please check if there is a problem with my $args array and i apply the pagination here, but wp-query is not working, here is my code, please give me a solution.

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

    $args = array(
      'posts_per_page' => 5,
      'post_type' => 'organisation',
      'paged' => $paged,
      'meta_query' => array(
          array(
            'key'     => 'title',
            'value'   => 'a',
            'compare' => 'LIKE',
          ),
        ),
         );

  $query = new WP_Query( $args );
        if ( $query->have_posts() ) {
        foreach ( $query as $post ) 
        {
            setup_postdata ( $post ); 
            ?> 
           <div class="col-md-4 org-logo" style="text-align:center;">
              <div class="pr_image">
                <?php
                 if ( has_post_thumbnail($post->ID))
                  {
                    $thumbnail = get_the_post_thumbnail($postid, array( 80, 80)); 
                    echo '<a href='.get_permalink( $postid ).' title="'.get_the_title().'">'.$thumbnail.'</a>';  
                  }
                ?>    
              </div>
              <?php 
                $shortname =  get_post_meta($post->ID,'short_name',true); 
                $title =  get_the_title(); 
                 if(!empty($shortname))
                 {
                  echo '<span>' .$shortname. '</span>';
                 }
                 else
                 {
                  echo '<span>' .$title. '</span>';
                 }
              ?>
          </div>
        <?php 
            }
          }
     else 
     {
        ?> 
        <div class="alert">Sorry, No organisation found.</div>
        <?php
     }
?>
<?php
  $big = 99999; // need an unlikely integer
  echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $the_query->max_num_pages
  ) );



     ?>

Read more here: error with $query->have_posts()


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: