Custom Post Types: $paged variable always 1
-
Hello,
Trying to paginate with custom post types:
– The first 6 lines shows in …./my-account/license-keys/
– The bottom of this page shows: Page 1 of 4 | 1 2 3 4 | next
– Selecting page 2 opens this URL: …./my-account/license-keys/page/2 but shows page 1 content.The permalink is configured as /%postname%/%post_id%/
What is wrong with my code:
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$temp = $wp_query; // re-sets query
$wp_query = null; // re-sets query$args = array(
‘post_type’ => ‘invite_codes’,
‘posts_per_page’=> 5,
‘orderby’ => array(
‘PO’ => ‘ASC’ ),
‘paged’ => $paged,
‘post_status’ => array(‘publish’, ‘draft’),
‘meta_query’ => array(
array(
‘key’ => ‘NIT’,
‘value’ => $nit_user,
‘compare’ => ‘=’
),
)
);$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) :
while( $wp_query -> have_posts() ) : $wp_query->the_post(); ?>
// loop
endwhile;
else : ?>
<p><b>No record found.</b> </p>
<?php
endif;echo ‘<div class=”pagination”>’;
if(function_exists(‘wp_pagenavi’)) { wp_pagenavi(array( ‘query’ => $wp_query )); }
echo ‘</div>’;
$wp_query = null;
$wp_query = $temp; // Reset
wp_reset_postdata();Please your help.
Thank you.
Marcelo
- The topic ‘Custom Post Types: $paged variable always 1’ is closed to new replies.