0

i have created a php template for a page and displaying posts from my custom post type, but i am skiping posts according to the followed condition.

so this is my page template code.

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$args = array( 
         'post_type' => 'custom-post-type', 
         'paged'     => $paged,
         'order_by'  => 'DESC',
         'posts_per_page' => 10, //my posts count, but on page post count mismatch
         'meta_value' => 'someMetaVale',   
      );
$query= WP_query($args);
  while ( $query->have_posts() ) {
    $query->the_post(); 
   $meta_value = get_post_meta(get_the_ID,'some_meta_key',true);
    $post_args = array( 
         'post_type' => 'post', 
         'posts_per_page' => 1,
         'meta_value' => $meta_value,   
      );
       $result = get_posts($post_args);
       if(!empty($result[0]->ID)) // here is my condition where i am skipping posts.
       {
             the_title(); //here i am printing post title
       }
   }
 <div class="dt-pagination-nav">
                <?php if ($query->max_num_pages > 1) 

            { // check if the max number of pages is greater than 1 

             ?>
            <?php
            $big = 999999999; // need an unlikely integer

            echo paginate_links( array('base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
              'format'          => 'page/%#%',
              'current' => max( 1, get_query_var('page') ),
              'total' => $query->max_num_pages,
              'add_fragment'    => '',
            ));
            ?>
            <?php } ?>
            </div>`

Problem arises is that i have mismatch of posts in page, because of posts that i am skipping, so please suggest a solution for which i can skip posts as well and also make my count correct

  • Why you are skipping the posts? And why you are checking posts again with same meta_value that you get in loop? – Khushboo Jan 12 '18 at 14:09
  • Hi! I am skipping posts of same meta value becoz these posts are of different types. – Jay Kapoor Jan 15 '18 at 4:19
0

I suggest you try resolving this in the wp query with meta query. This might help you.

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.