custom post type: recognized number of pages but link to page don't work
-
Hello,
I’m using wp_pagenavi in a custom loop in Custom post type for projects and although it shows number of pages for pagination, the links to next and previous page don’t work, I do clic to page 2 but it goes to /page/2/ in the url but it doesn’t change the shown projects and number of page which wp_pagenavi shows it is still in page 1.
My code is:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Query arguments $args = array( 'posts_per_page' => $results, 'ignore_sticky_posts' => 0, 'post_type' => 'proyecto', 'orderby' => $val_orderby, 'paged' => get_query_var( 'page' ), 'tax_query' => array( array( 'taxonomy' => 'proyecto-type', 'field' => 'id', 'terms' => $exclude, 'operator' => 'NOT IN' ) ) ); $post_query = new WP_Query($args); // At first, we assign the post results to a variable. We do this first, in order to get the // specific categories present (avoiding this way, to show an empty category tab) if( $post_query->have_posts() ) { // The loop $section_posts = ''; while ($post_query->have_posts()) { $post_query->the_post(); // Set the array that will contain all the resulted posts categories $categories = array(); $fechas = array(); // Get the post's categories (use wp_get_object_terms for custom post type) $post_categories = wp_get_object_terms( get_the_ID(), 'proyecto-type' ); // Get the post's categories (use wp_get_object_terms for custom post type) $post_fechas = wp_get_object_terms( get_the_ID(), 'proyecto-fecha' ); $post_cat_classes = ''; $post_cat_names = ''; $post_fecha_classes = ''; $post_fecha_names = ''; if (!empty($post_categories) && !is_wp_error( $post_categories ) ) { // Set the variable that will contain all the categiry selector classes foreach ($post_categories as $category) { $categories[] = $category->name; $post_cat_classes .= strtolower(sanitize_html_class( $category->name )) .' '; $post_cat_names .= $category->name .' '; } } if (!empty($post_fechas) && !is_wp_error( $post_fechas ) ) { // Set the variable that will contain all the categiry selector classes foreach ($post_fechas as $fecha) { $fechas[] = $fecha->name; $post_fecha_classes .= strtolower(sanitize_html_class( $fecha->name )) .' '; $post_fecha_names .= $fecha->name .' '; } } // Prepare posts section if ($val_layout == 'portfolio_strict') { $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), $thumbsize) ; $section_posts .= '<div class="'. $post_cat_classes .'col-xs-12 col-sm-6 col-md-'. $val_cols .' col-lg-'. $val_cols .'">'."\n"; $section_posts .= ' <div class="proyecto_item col-md-12">'."\n"; $section_posts .= ' <div class="col-md-5 col-xs-12 img-proyecto">'."\n"; $section_posts .= ' <img src="'. esc_url( $thumb_url[0] ) .'" alt="'. esc_attr( get_the_title() ) .'" />'."\n"; $section_posts .= ' </div>'."\n"; $section_posts .= ' <div class="proyecto_description col-md-7 col-xs-12"><h2 class="titulo-proyecto">'. get_the_title() .'</h2>'."\n"; $section_posts .= ' <p class="texto-proyecto">'. get_the_content() ."\n"; $section_posts .= ' <div class="datos-extra">'."\n"; foreach ($categories as $categorykey=>$categoryname) { $section_posts .= ' <p class="tipo-proyecto">'. $categoryname .'</p>'."\n"; } foreach ($fechas as $fechakey=>$fechaname) { $section_posts .= ' <p class="fecha-proyecto">'. $fechaname .' </p>'."\n"; } $section_posts .= ' </div>'; $section_posts .= ' </div>'; $section_posts .= ' </div>'."\n"; $section_posts .= '</div>'."\n"; } else { $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), $thumbsize) ; $section_posts .= '<div class="'. $post_cat_classes .'col-xs-12 col-sm-6 col-md-'. $val_cols .' col-lg-'. $val_cols .'">'."\n"; $section_posts .= ' <div class="proyecto_item col-md-12">'."\n"; $section_posts .= ' <div class="col-md-5 col-xs-12 img-proyecto">'."\n"; $section_posts .= ' <img src="'. esc_url( $thumb_url[0] ) .'" alt="'. esc_attr( get_the_title() ) ."\n"; $section_posts .= ' </div>'.'\n'; $section_posts .= ' <div class="proyecto_description col-md-7 col-xs-12"><h2 class="titulo-proyecto">'. get_the_title() .'</h2>'."\n"; $section_posts .= ' <p class="texto-proyecto">'. get_the_content() ."\n"; $section_posts .= ' <div class="datos-extra">'."\n"; foreach ($categories as $categorykey=>$categoryname) { $section_posts .= ' <p class="tipo-proyecto">'. $categoryname .'</p>'."\n"; } foreach ($fechas as $fechakey=>$fechaname) { $section_posts .= ' <p class="fecha-proyecto">'. $fechaname .' </p>'."\n"; } $section_posts .= ' </div>'; $section_posts .= ' </div>'; $section_posts .= ' </div>'."\n"; $section_posts .= '</div>'."\n"; } }//while //Navigation Code if ( $post_query->max_num_pages > 1 ) { echo $post_query->max_num_pages; echo '<nav class="post-navigation">'; echo '<h3 class="assistive-text">'. _e( 'Post navigation', 'cleanstart' ) .'</h3>'; if ( function_exists('wp_pagenavi' ) ) { wp_pagenavi( array( 'query' => $post_query ) ); echo '1a'; } elseif ( function_exists('wp_page_numbers' ) ) { wp_page_numbers(); echo '2b'; } else { next_posts_link( 'Older posts', $post->max_num_pages ); previous_posts_link('<'); echo '3c'; } echo '</nav><!-- #nav -->'; } wp_paginate(); } else { return; } wp_reset_query(); return $section_posts ; } }
I don’t know if someone can help me.
Thank you very much in advance,
Zaida
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘custom post type: recognized number of pages but link to page don't work’ is closed to new replies.