0

I am trying to pagging my taxonomy-products_categories.php. But unfortunatily it throw me to 404.php page rather then page/2. Following is my code for custom post type and its taxonomy.

$labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name'),
'menu_name' => 'Products'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true, 
'show_in_menu' => true, 
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' )
); 
register_post_type('products',$args);

taxonomy

$labels = array(
    'name' => _x( 'Product Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Product Category', 'taxonomy singular name' ),
    'menu_name' => __( 'Product Categories' )
);

register_taxonomy('product_categories',array('products'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'query_var' => true,
    'show_ui' => true
));

My taxonomy-product_categories.php loop

$post_type_link = (get_post_type_archive_link(get_post_type()));
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$al_cat_slug = get_queried_object()->slug;
$al_cat_name = get_queried_object()->name;
$al_tax_post_args = array(
    'post_type' => 'products',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'paged' => $paged,
    'posts_per_page' => 1,
    /*'exclude' => array(29),*/
    'caller_get_posts'=> 1,
    'tax_query' => array(
        array(
            'taxonomy' => 'product_categories',
            'field' => 'slug',
            'terms' => $al_cat_slug,
        ),
        'include_children' => false,
    )
);
$al_tax_post_qry = new WP_Query($al_tax_post_args);


    if($al_tax_post_qry->have_posts()) :
                    while($al_tax_post_qry->have_posts()) :
                        $al_tax_post_qry->the_post();

                        echo '<div class="col-lg-4 col-md-4 col-sm-4 col-xs-6">';
                        echo '<a href="'.get_the_permalink().'">';
                        if (has_post_thumbnail()){
                            echo get_the_post_thumbnail( $post_id, 'medium', array('class'=>'img-fluid') );
                        }
                        echo '</a><br>';
                        echo 'Name: <a href="' . get_the_permalink() . '" class="product-title">'.get_the_title().'</a><br>';
                        $price = get_post_meta($post->ID,'price', true);
                        echo 'Price: ' . $price;
                        echo '</div>';
                    endwhile;
                endif;

and paging is

    $big = 999999999;
                echo paginate_links(
                    array(
                        'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $al_tax_post_qry->max_num_pages,
                        'prev_text' => __( '&laquo;', 'textdomain' ),
                        'next_text' => __( '&raquo;', 'textdomain' ),
                    )
                );


kindly advice what should I do.
  • Code seems ok. Try flushing the permalinks. Go to Settings -> Permalinks and click 'Save Changes`. This refreshes the permalinks. Let us know what happens. – Nilambar May 15 at 7:52
  • @Nilambar except there is no caller_get_posts parameter, posts_per_page is specified twice and $al_cat_name is never used. – Max Yudin May 15 at 8:22
  • Thats why i'm surprise that why its throwing me to 404 page. I have tried flushing the permalinks. nothing happens. It keep showing error... – John Paul May 15 at 8:51
  • any one can guid – John Paul May 16 at 4:41

Your Answer

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

Browse other questions tagged or ask your own question.