WordPress.org

Ready to get started?Download WordPress

Forums

Custom Taxonomy Navigation Problem: paged=1 works, paged=2 doesnt (14 posts)

  1. Vlad Nicula
    Member
    Posted 3 years ago #

    The context:
    Problematic Page

    This is a site that has a custom post type and a custom taxonomy. The link get's you on one custom taxonomy page.

    Pagination does not work on this host, but it works on local host, so the same theme on my Linux Localhost works, but it doesn't on my actual host.

    Wp-pagenavi and previews and next page links are installed for debugging.

    I tested with and without plugins. The language plugin does not change a thing regarding the way the pagination works.

    Paged=1 works. Paged=2 throws me to the 404 page. It's like worpdress.. or my host doesn't like other pages expect paged=1.

    Any hints? I would really appreciate it.

    Oh yes, and here is the way I get the paged variable:

    query_posts(array('post_type' => 'LOBJ_Product',
    			'paged' => get_query_var( 'paged' ),
    			'posts_per_page' => 4
    ) );

    Again, it works on localhost, it doesn't on my deployment server. I don't know much about .httaccess and mod rewrite or anything like that, but I am not using friendly urls, as you can see.

    Thank you for your time :D

  2. scribu
    Member
    Posted 3 years ago #

    If it works on your localhost and it doesn't work live, and it's the same code, then it means the problem is somewhere in the live database (settings, active plugins, etc.)

  3. Vlad Nicula
    Member
    Posted 3 years ago #

    Thanks for your replay scribu, I thought about it and I can't seem to find out why this happens. I will try to use the theme on a fresh wordpress installation and see how that works.

    There were some other problems with wordpress 3.1. For example, my custom post type name had uppercase letters. I must have skipped the line from the codex page that said we should not use uppercase letters.

    Now all the old products have the post_type = "LOBJ_Product" and the new ones have post_type = "lobj_product". Luckily I was able to fix this with a simple SQL Update wp_posts SET post_type = "lobj_product" where post_type = "LOBJ_Product" but anyway, quite a bad move they did with 3.1...

  4. Vlad Nicula
    Member
    Posted 3 years ago #

    I tried with a new installation and it still doesn't work. http://webcodetuts.com/lesobjects.ro/?taxonomy=lobj_product_category&term=handmade

    Why is this happening ONLY on my host, and not on my localhost? :|

  5. scribu
    Member
    Posted 3 years ago #

    It seems to be working fine now.

  6. Vlad Nicula
    Member
    Posted 3 years ago #

    I make a patch for it. On my 404.php template I check to see if paged and taxonomy variables are set in get_query_vars. If true, I include the taxonomy-mytaxonomyname.php instead of the rest of the 404 page.

    Not the best, but it works... There are so many reasons this is not a good move, but hey, I think they will fix this soon.

  7. AntonyC
    Member
    Posted 3 years ago #

    Hi, I'm having issues with paginated taxonomies (and blog) with WP 3.1 too. Both with my own theme and the 'Lotus' theme that I tried recently!!

    Is there a fix that anyone knows of?

    Many thanks,

    Antony

  8. cornhustlah
    Member
    Posted 3 years ago #

    @agilius:

    can you elaborate on your solution here?

  9. cornhustlah
    Member
    Posted 3 years ago #

    OK :::

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    should actually be:

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;

    see here:
    http://wordpress.stackexchange.com/questions/16353/custom-taxonomy-not-working-with-posts-per-page-in-new-wp-query-pagination-probl

  10. cornhustlah
    Member
    Posted 3 years ago #

    i should also mention that next_posts_link(), previous_posts_link() and posts_nav_link() all pull up a faulty URL and i had to catch this custom setup for pagination:

    <?php // OK, custom tax's dont work nice with query_posts (i think) but they DEF dont work nice with next_posts(), previous_posts() and  posts_nav_link()
                  // SO, got the custom page nav from here:
                  // http://wordpress.org/support/topic/adding-pagination-to-a-wp_query-loop?replies=16
            if($taxquery->max_num_pages>1){
              if ($paged > 1) { ?>
                <a href="<?php echo '?page=' . ($paged -1); //prev link ?>"><</a>
              <?php
              }
              for($i=1;$i<=$taxquery->max_num_pages;$i++){?>
                <a href="<?php echo '?page=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
              <?php
              }
              if($paged < $taxquery->max_num_pages){?>
                <a href="<?php echo '?page=' . ($paged + 1); //next link ?>">></a>
              <?php
              }
            }?>

    which i based off this semi-related support topic:
    http://wordpress.org/support/topic/adding-pagination-to-a-wp_query-loop?replies=16

    :D

  11. Vlad Nicula
    Member
    Posted 3 years ago #

    @cornhustlah

    Thanks for the page vs paged hint. I found it out on my own and didn't know why it happened.

    To explain what I did with the 404 problem.

    On my 404.php I had something like

    if(/* see if paged var exists, and some other condition indicating that I have a cusotm taxonomy present*/) : redirect to taxonomy template; else : do 404; endif;

    This works in some very few cases, but hey :) it fixed it for me. It's a small site anyway.

  12. xpert6
    Member
    Posted 2 years ago #

    I have a same issue guyz please help me out

    Here is my code for register custom post type and taxonomy

    add_action('init', 'ep_add_equipment');
    function ep_add_equipment()
    {
    $labels = array(
    'name' => _x('Equipments', 'post type general name', 'epanel'),
    'singular_name' => _x('Equipments', 'post type singular name', 'epanel'),
    'add_new' => _x('Add New Equipment', 'slide', 'epanel'),
    'add_new_item' => __('Add New Equipment', 'epanel'),
    'edit_item' => __('Edit Equipment', 'epanel'),
    'new_item' => __('New Equipment', 'epanel'),
    'view_item' => __('View Equipments', 'epanel'),
    'search_items' => __('Search Equipments', 'epanel'),
    'not_found' => __('No Equipments found', 'epanel'),
    'not_found_in_trash' => __('No Equipments found in Trash', 'epanel'),
    'parent_item_colon' => ''
    );
    $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'products'),
    'capability_type' => 'post',
    'exclude_from_search' => true,
    'hierarchical' => true,
    'menu_icon' => get_template_directory_uri() .'/images/equipment.png',
    'menu_position' => 5,
    'can_export' => true,
    'supports' => array('title','editor','thumbnail', 'comments','page-attributes','excerpt'/*,'author','excerpt'*/),
    );
    register_post_type('equipment',$args);

    register_taxonomy('equipments', 'equipment', array('hierarchical' => true, 'show_in_nav_menus' => true, 'show_ui' => true,
    'query_var' => true, 'labels' => array('name' => __( 'Equipments Categories' ), 'singular_label' => __('Category'), 'add_new_item' => __( 'Add New Category' ), 'search_items' => __( 'Search Categories' )), 'rewrite' => array('slug' => 'equipments')));

    }

    function add_menu_admin_bar() {
    global $wp_admin_bar;

    if ( !is_super_admin() || !is_admin_bar_showing() )
    exit;

    // $wp_admin_bar->add_menu( array( 'id' => 'theme_options', 'title' =>__( 'E-Panel', 'epanel' ), 'href' => admin_url('admin.php')."?page=epanel_settings" ) );
    $wp_admin_bar->add_menu( array( 'id' => 'equipment', 'title' =>__( 'Equipments', 'epanel' ), 'href' => admin_url('edit.php')."?post_type=equipment" ) );

    $wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Add New Equipment', 'epanel' ), 'href' => admin_url('post-new.php')."?post_type=equipment" ) );
    $wp_admin_bar->add_menu( array( 'parent' => 'equipment', 'title' =>__( 'Equipment Categories', 'epanel' ), 'href' => admin_url('edit-tags.php')."?taxonomy=equipment_categories&post_type=equipment" ) );

    }
    add_action( 'admin_bar_menu', 'add_menu_admin_bar' , 70);

    Loop code for taxonomy.php

    <?php
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
    'taxonomy' => $term->taxonomy,
    'term' => $term->slug,
    'post_type' => 'equipment',
    'paged'=> $paged,
    /*'posts_per_page' => 10,*/
    'caller_get_posts'=> 1
    );
    ?>
    <?php query_posts( $args ); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

  13. cospefogo
    Member
    Posted 2 years ago #

    Hey people!

    There is a well hidden trap on this subject!
    I was having a problem of a 404 error on every time I tried to navigate to the second page of a custom post page. After few tries I did narrow down the problem! It was related to my permalinks and my slugs!

    My custom post was called (slug):
    PREVIEWS
    My page was also called (slug):
    PREVIEWS

    This makes the pagination not work, and the only way to correct it is:

    1 - You need to change the slug of your page, for example:
    MY-PREVIEWS

    2 - Or you need to change the slug of your custom post, for example:
    LIST-OF-PREVIEWS

    3 - Or, if you are using the Custom Post Type UI plugin, you can easily just adjust the rewrite slug of the custom post to, for example:
    PREVIEW

    And at last, not least, remember:
    Custom post navigation will work only with:
    query_posts($args)

    It will never work with
    $query = new WP_query($args)

    Regards,
    Cospefogo.

  14. petra5
    Member
    Posted 2 years ago #

    Why it It will never work with
    $query = new WP_query($args)?

    I am using new WP_query for this

Topic Closed

This topic has been closed to new replies.

About this Topic