I created custom taxonomy and registered it with "Pages" with the following code
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_Offer_Categorys_hierarchical_taxonomy', 0 );
//create a custom taxonomy name it Offer Categorys for your posts
function create_Offer_Categorys_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Offer Category', 'offer Categories general name' ),
'singular_name' => _x( 'Offer Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Offer Category' ),
'all_items' => __( 'All Offer Categorys' ),
'parent_item' => __( 'Parent Offer Category' ),
'parent_item_colon' => __( 'Parent Offer Category:' ),
'edit_item' => __( 'Edit Offer Category' ),
'update_item' => __( 'Update Offer Category' ),
'add_new_item' => __( 'Add New Offer Category' ),
'new_item_name' => __( 'New Offer Category Name' ),
'menu_name' => __( 'Offer Category' ),
);
// Now register the taxonomy
register_taxonomy('offer-category',array('page'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'exclude_from_search' => false,
'rewrite' => array( 'slug' => 'offer-category' ),
));
}
Then I created a template file named taxonomy-offer-category.php
Issue is pagination is not working as it should be. After writing the code of pagination, paging url coming like this '/offer-category/automobile/page/2', etc
but this page is giving error (404) but when I manually hit url like
/offer-category/automobile?page=2 then this gives the result.I dont know whats the issue. below is the code for pagination
$term_id=get_queried_object()->term_id;
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
// echo $paged;
$args = array(
'post_type' => 'page',
'paged' => $paged,
'posts_per_page' => '1',
'tax_query' => array(
array( 'taxonomy' => 'offer-category',
'field' => 'id',
'terms' => $term_id
)
),
);
wp_reset_query();
//$page_args=array('post_type' => 'page');
$query = new WP_Query($args);
$big = 999999999; // need an unlikely integer
$links = paginate_links( array(
'current' => max( 1, get_query_var('page') ),
'total' => $query->max_num_pages,
'prev_text' => '<',
'next_text' => '>',
'type' => 'array'
) );
I have tried all the possible answers of google like using format, using paged instead of page etc and this issue is a long time back issue and I dont know whether it is fixed or not. Can you guys please help me in that.
Thanks.