• Good day,

    I am currently working on using a custom wp_query on a custom taxonomie page.
    The moment I want to go to page 2 on this page I get to see a 404 page.

    I have tried many different options but I get nothing working.
    Below the code for the taxonomie page with the pagination in it.

    <?php get_header(); ?>
    
    <?php
    $term = get_queried_object();
    if(get_field('slider_shop_overzicht','option')){
    	$term_slider = get_field('slider_all_category',$term);
    	echo do_shortcode( '[slider slug="'. $term_slider->slug .'"]' );
    }
    ?>
    
    <main>
    
    	<div class="row alt_overzicht_tax">
    
    		<div class="full-row">
    
    			<div class="blocks-container">
    
    				<div class="block titel">
    
    					<h1> <?php echo $term->name;?> </h1>
    
    					<?php
    
    						$parentId = $term->parent; 
    						$parentObj = get_term_by('id', $parentId, 'alt_products_tax');
    					?>
    
    					<?php if(!empty($parentObj)){ ?>
    
    						<div class="back-to">
    							
    							<a href="<?php echo get_term_link($parentObj);?>"> go back to <?php echo $parentObj->name;?>  </a>
    
    						</div>
    
    					<?php  }else{  ?>
    						
    						<?php if(get_field('alt_product_overzicht_pagina_link','options')){ ?>
    
    							<?php if(get_field('alt_product_overzicht_pagina_link','options')['url'] && get_field('alt_product_overzicht_pagina_link','options')['title']){ ?>
    
    								<div class="back-to">
    									
    									<a href="<?php echo get_field('alt_product_overzicht_pagina_link','options')['url'];?>"> <?php echo get_field('alt_product_overzicht_pagina_link','options')['title'];?> </a>
    
    								</div>
    								
    							<?php } ?>
    							
    						<?php } ?>
    
    					<?php } ?>
    
    				</div>
    
    				<?php 
    			
    					$terms = get_terms( array(
    						'taxonomy' => 'alt_products_tax',
    						'orderby'	=> 'count',
    						'hide_empty' => false,
    						'parent' =>  $term->term_id,
    					) );
    					
    				?>
    
    				<?php $terms_child = get_term_children( $term->term_id, 'alt_products_tax' ); ?>
    
    				<?php if ( !empty( $terms ) && !is_wp_error( $terms ) ){ ?>
    
    					<div class="block overzicht-tax">
    
    						<?php foreach($terms as $term){ ?>
    
    							<div class="alt_tax_item" <?php if(get_field('afbeelding_alt_category',$term)){ ?> style='background-image:url("  <?php echo the_field('afbeelding_alt_category',$term);?> ");' <?php } ?> >
    
    								<a href="<?php echo get_term_link($term);?>">
    
    									<div class="titel">
    										
    										<p> <?php echo $term->name;?> </p>
    
    									</div>
    
    								</a>
    
    							</div>
    
    						<?php } ?>
    
    					</div>
    
    				<?php } ?>
    
    				<?php 
    					$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; 
    					$args = array(
    
    						'post_type' => array('alt_product'),
    						'posts_per_page' => 1, 
    						'posts_per_archive_page' => 1,
    						'paged'				=> $paged,
    						'page' => $paged
    					);
    					$alt_product_query = new WP_Query($args);
    					
    				?>
    
    				<?php if($alt_product_query->have_posts()){ ?>
    
    					<div class='block overzicht-alt-product'>
    
    						<?php while($alt_product_query->have_posts()) { $alt_product_query->the_post(); ?>
    
    							<?php the_title();?>
    
    						<?php };?>
    
    					</div>
    
    				<?php // 3- Appel de la fonction paginate_links
    					$big = 999999999;
    
    					echo paginate_links( array( // Plus d'info sur les arguments possibles : https://codex.www.ads-software.com/Function_Reference/paginate_links
    						'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    						'format' => '?paged=%#%',
    						'current' => max( 1, get_query_var('paged') ),
    						'total' => $alt_product_query->max_num_pages
    					) ); 
    				//Fin de la fonction paginate_links
    			?> 
    
    				<?php } wp_reset_postdata();  ?>
    			</div>
    
    		</div>
    
    	</div>
    
    </main>
    
    <?php get_footer(); ?>

    I would like to know if someone has already solved this problem.

    thanks in advance

    • This topic was modified 5 years, 4 months ago by bcworkz. Reason: code fixed

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @mauroburo210

    Please try after saving the permalinks.

    Thread Starter mauroburo210

    (@mauroburo210)

    Hey Adnan,

    I did save the permalinks again and nothing changed.

    Moderator bcworkz

    (@bcworkz)

    The 404 is because there is no page 2 for the main query. WP thinks you want a second page of terms and not another post. To avoid confusing WP, I suggest abandoning “paged” and related WP_Query arguments. Use your own unique paging var in place of paged and use the “offset” query argument to get to the desired post for the requested page. You could whitelist your unique paging var through the “query_vars” filter, or simply get it out of the $_GET array. Type cast any integer value taken from $_GET with (int) to secure against any sort of SQL injection attack.

    BTW, the triple backtick markdown for code blocks doesn’t work with forum posts. Just use a single backtick, ensuring it’s the first char on a line (col 0).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom taxnomy page’ is closed to new replies.