-1

I am new in wordpress, I want show pagination in custom post type query but pagination not show in frontend, can any one see my code where i am doing wrong:

  <?php 
// the query

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

$wpb_all_query = new WP_Query(array('post_type'=>'german_post', 'post_status'=>'publish', 'posts_per_page'=>12,'order' => 'DESC','paged' => $paged,'orderby' => 'date'));

 ?>
    <?php if ( $wpb_all_query->have_posts() ) : ?>
    <div class="row" id="post_content">
      <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
      <div class="col-md-4 col-sm-6 col-xs-12" id="post_container">
        <div class="post-box" > 
            <a href="<?php the_permalink(); ?>" class="clickable_box"></a>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
          <div class="post-img" style="background-image:url(<?php the_post_thumbnail_url(); ?>)">
            <?php if ( has_post_thumbnail() ) : ?>
            <?php endif; ?>
          </div>
          </a>
          <div class="post-small-details"> <span class="interests">
            <ul class="list-inline">
              <li><?php echo get_the_term_list(get_the_ID(), 'geram_category'); ?></li>
            </ul>
            </span> <span class="divider">&nbsp;/</span>
            <div class="post-created"><?php echo get_the_date('d.m.Y',$post->ID);?></div>
            <div class="clear-both"></div>
          </div>
          <div class="post-title-container">
            <div class="post-title">
              <h2>
                <?php  $content = get_the_title();
                                   $content = strip_tags($content);
                                          echo substr($content, 0, 65); ?>
              </h2>
            </div>
          </div>
          <div class="post-details">
            <?php the_excerpt();?>
          </div>
          <div class="like_box gr_like_box">

                                <ul>

                                    <li class="share_post">
                                        <img src="<?php echo get_template_directory_uri (); ?>/images/share.svg" width="34px">
                                        <div class="post_share">
                                            <a href="https://plus.google.com/share?url=<?php the_permalink(); ?>" onclick="javascript:window.open(this.href,
  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/gplus.svg" width="25px">
                                        </a>
                                       <a href="http://twitter.com/home/?status=<?php the_title(); ?> - <?php the_permalink(); ?>" title="Tweet this!">
                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/twitter.svg" width="25px">
                                        </a>
                                        <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php the_title(); ?>" title="Share on Facebook." target="_blank">
                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/facebook.svg" width="25px">
                                        </a>
                                        <a href="http://www.reddit.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title(); ?>" title="Vote on Reddit">

                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/reddit.svg" width="25px">
                                        </a>
                                        <a href="http://pinterest.com/pin/create/button/?url=<?php the_title(); ?> - <?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $url; ?>">
                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/pinterest.svg" width="25px">
                                        </a>
                                        <a href="mailto:?subject=<?php the_title(); ?>&amp;body=<?php the_permalink(); ?>" title="Contact us">
                                            <img src="<?php echo get_template_directory_uri (); ?>/images/article_share_img/email.svg" width="25px">
                                        </a>
                                        </div>

                                    </li>

                                    <li><?php  echo CS_Likes::show_buttons_like(); ?></li>

                                </ul>
                            </div>
        </div>
      </div>
      <?php endwhile; ?>
      <!-- end of the loop -->

      <?php wp_reset_postdata(); ?>
    </div>
    <div class="loader-box">
      <?php the_posts_pagination(); ?>
    </div>
    <?php else : ?>
    <p>
      <?php _e( 'Leider gibt es keinen Treffer, der mit dem Suchbegriff übereinstimmt. Ändern Sie das Suchwort und versuchen Sie es bitte erneut.' ); ?>
    </p>
    <?php endif; ?>
  • Why are you using a custom query? – Jacob Peattie Aug 23 '18 at 10:01
  • Hey @JacobPeattie I am new in wordpress, I just copy paste it, Can you tell what should i do ? – Shiva Aug 23 '18 at 10:04
  • have you tried searching here? this question has been asked many times. – Milo Aug 23 '18 at 15:39
0

As far I read in your comment, it isn't requires for you to handle it with a custom query. So if you register your custom post type with 'has_archive' => true, then you can just reach the archive of the custom post type at http://www.yourwebsite.com/your-cpt-slug/.

Important: Remember to flush the rewrite rules after you change somethign related to your permalinks. You can do it just visiting Settings > Permalinks

See how register_post_type works for any doubt, it's always lighting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.