0

I have problem with pagination. For archive page, pagination works perfectly.

Example url: https://www.example.com/tum-urunler/page/2/ (tum-urunler is archive slug for custom post type "urun")

But if i add taxonomy parameters pagination not working.

Example url:https://www.example.com/tur/bebek/page/2/ (tur is taxonomy and bebek is term)

It redirects me 404.php. So i dumped wp_query in 404.php and i saw paged is 0. Here is my dumped wp_query when pagination not working

object(WP_Query)#73 (50) { ["query"]=> array(2) { ["post_type"]=> string(4) "urun" ["tur"]=> string(1) "2" } ["query_vars"]=> array(67) { ["post_type"]=> string(4) "urun" ["tur"]=> string(1) "2" ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(0) "" ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> int(0) ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["s"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["post_name__in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["post_parent__in"]=> array(0) { } ["post_parent__not_in"]=> array(0) { } ["author__in"]=> array(0) { } ["author__not_in"]=> array(0) { } ["ignore_sticky_posts"]=> bool(false) ["suppress_filters"]=> bool(false) ["cache_results"]=> bool(true) ["update_post_term_cache"]=> bool(true) ["lazy_load_term_meta"]=> bool(true) ["update_post_meta_cache"]=> bool(true) ["posts_per_page"]=> int(10) ["nopaging"]=> bool(false) ["comments_per_page"]=> string(2) "50" ["no_found_rows"]=> bool(false) ["taxonomy"]=> string(3) "tur" ["term"]=> string(1) "2" ["order"]=> string(4) "DESC" } ["tax_query"]=> object(WP_Tax_Query)#2946 (6) { ["queries"]=> array(1) { [0]=> array(5) { ["taxonomy"]=> string(3) "tur" ["terms"]=> array(1) { [0]=> string(1) "2" } ["field"]=> string(4) "slug" ["operator"]=> string(2) "IN" ["include_children"]=> bool(true) } } ["relation"]=> string(3) "AND" ["table_aliases":protected]=> array(0) { } ["queried_terms"]=> array(1) { ["tur"]=> array(2) { ["terms"]=> array(1) { [0]=> string(1) "2" } ["field"]=> string(4) "slug" } } ["primary_table"]=> string(8) "tr_posts" ["primary_id_column"]=> string(2) "ID" } ["meta_query"]=> object(WP_Meta_Query)#2947 (9) { ["queries"]=> array(0) { } ["relation"]=> NULL ["meta_table"]=> NULL ["meta_id_column"]=> NULL ["primary_table"]=> NULL ["primary_id_column"]=> NULL ["table_aliases":protected]=> array(0) { } ["clauses":protected]=> array(0) { } ["has_or_relation":protected]=> bool(false) } ["date_query"]=> bool(false) ["queried_object"]=> NULL ["queried_object_id"]=> NULL ["request"]=> string(296) "SELECT SQL_CALC_FOUND_ROWS tr_posts.ID FROM tr_posts WHERE 1=1 AND ( 0 = 1 ) AND tr_posts.post_type = 'urun' AND (tr_posts.post_status = 'publish' OR tr_posts.post_status = 'acf-disabled' OR tr_posts.post_status = 'private') GROUP BY tr_posts.ID ORDER BY tr_posts.post_date DESC LIMIT 0, 10" ["posts"]=> &array(0) { } ["post_count"]=> int(0) ["current_post"]=> int(-1) ["in_the_loop"]=> bool(false) ["comment_count"]=> int(0) ["current_comment"]=> int(-1) ["found_posts"]=> int(0) ["max_num_pages"]=> int(0) ["max_num_comment_pages"]=> int(0) ["is_single"]=> bool(false) ["is_preview"]=> bool(false) ["is_page"]=> bool(false) ["is_archive"]=> bool(false) ["is_date"]=> bool(false) ["is_year"]=> bool(false) ["is_month"]=> bool(false) ["is_day"]=> bool(false) ["is_time"]=> bool(false) ["is_author"]=> bool(false) ["is_category"]=> bool(false) ["is_tag"]=> bool(false) ["is_tax"]=> bool(false) ["is_search"]=> bool(false) ["is_feed"]=> bool(false) ["is_comment_feed"]=> bool(false) ["is_trackback"]=> bool(false) ["is_home"]=> bool(false) ["is_404"]=> bool(true) ["is_embed"]=> bool(false) ["is_paged"]=> bool(false) ["is_admin"]=> bool(false) ["is_attachment"]=> bool(false) ["is_singular"]=> bool(false) ["is_robots"]=> bool(false) ["is_posts_page"]=> bool(false) ["is_post_type_archive"]=> bool(false) ["query_vars_hash":"WP_Query":private]=> string(32) "51d66ab84e27563088d67225fda32f66" ["query_vars_changed":"WP_Query":private]=> bool(false) ["thumbnails_cached"]=> bool(false) ["stopwords":"WP_Query":private]=> NULL ["compat_fields":"WP_Query":private]=> array(2) { [0]=> string(15) "query_vars_hash" [1]=> string(18) "query_vars_changed" } ["compat_methods":"WP_Query":private]=> array(2) { [0]=> string(16) "init_query_flags" [1]=> string(15) "parse_tax_query" } }

I don't know why page parameter un url not handled by wordpress. I need help. Thanks so much

  • Have you visited your permalinks page in the admin? – guiniveretoo Nov 11 '16 at 16:14
  • yes my permalinks are set to /%post_id%-%postname%/ but this should only effect single posts not taxonomy files. Am i right? – kenarsuleyman Nov 11 '16 at 17:26
  • It's look like tur is the paged value, does it work if you remove the taxonomy from the url and leave only the term ? – Benoti Nov 11 '16 at 17:30
  • No it is not working – kenarsuleyman Nov 11 '16 at 17:35
  • 1
    You have a rewrite rules conflict, please post both post type and taxonomy registration code. If you look at the query, you can see that WP is trying to query for the term with slug 2 in your taxonomy, which is obviously not correct. – Milo Nov 11 '16 at 17:52
0
function eg_add_rewrite_rules() {
    global $wp_rewrite;

    $new_rules = array( 

        '(tur|tip|tedarikci|beden|mevsim)/(.+)/?$' => 'index.php?post_type=urun&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)

    );
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );

I had this rewrite rule in my functions php. This was overwriting page variable. So i added one more rewrite rule to handle page variable. Here is last version of function

function eg_add_rewrite_rules() {
    global $wp_rewrite;

    $new_rules = array( 
        '(tur|tip|tedarikci|beden|mevsim)/(.+)/(page|paged)/(.+)/?$' => 'index.php?post_type=urun&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) .'&paged=' . $wp_rewrite->preg_index(4),

        '(tur|tip|tedarikci|beden|mevsim)/(.+)/?$' => 'index.php?post_type=urun&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)

    );
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.