WordPress.org

Forums

[resolved] Custom Post Type and Taxonomy pagination permalink 404 error (14 posts)

  1. xpert6
    Member
    Posted 3 years ago #

    Here is my code for register custom post type and taxonomy

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. xpert6
    Member
    Posted 3 years ago #

    Loop code for taxonomy.php

    [Code moderated as per the Forum Rules. Please use the pastebin]

  3. xpert6
    Member
    Posted 3 years ago #

    Please guyz help me my ............ i have created a custom page template and pagination is working fine on page

    http://www.kingdomcms.com/wordpress/mechnair/for-sale/

    but i need pagination on taxonomy.php file

    http://www.kingdomcms.com/wordpress/mechnair/equipments/for-sale/

  4. nackle2k10
    Member
    Posted 3 years ago #

    I got the same problem and still try to figure it out. Any luck?

  5. xpert6
    Member
    Posted 3 years ago #

    No dude i didnt find any solution but because i have limited categories so i have created pages for each category with same name and assigned that template. Pagination is working fine on custom page template. Here is my query for custom page template but i dont think it is the right way to do this.

    [Code moderated as per the Forum Rules. Please use the pastebin]

  6. nackle2k10
    Member
    Posted 3 years ago #

    thanks dude, at least there is a temporary solution that works. still trying to figure out the best solution. I found a pagination chaining tutorial by Justin Carroll in wptuts and the results for me is still the same but may be you can try that method and tell me whether it works or not

  7. xpert6
    Member
    Posted 3 years ago #

    Thanks for the link man but result is still same for me too :(

  8. nackle2k10
    Member
    Posted 3 years ago #

    Hey Dude, I found the way to get the pagination fix!!

    first thing you need to know is do not add custom query_posts at your taxonomy.php it will ruin the pagination so get rid of it.

    second remove the exclude_from_search -> true while registering the post type

    third don’t register custom taxonomy with priority lower than priority for registering associated post type.

    example

    add_action('init', 'custom_post_type_register', 0);
    add_action('init', 'custom_tax_register', 10);

    if you want to add custom query to your taxonomy instead of using query_posts, just create another functions in functions.php then using pre_get_posts filter

    function search_filter($query) {
    	if ( !is_admin() ) {
    	    if ($query->is_search) {
    			$query->set('post_type', array('post', 'page'));
    	    }
        }
        return $query;
    }
    add_filter('pre_get_posts', 'search_filter');

    This is use to filter the search to only search for post and page if you want to add the custom post type just append it in to the array.

    if you want to make custom post per page use this functions

    $option_posts_per_page = get_option( 'posts_per_page' );
    $option_taxposts_per_page = (int)(get_option('my_custom_option');
    if($option_taxposts_per_page['st_search_results_show'] == ''){ $option_taxposts_per_page = $options_posts_per_page;}
    
    add_action( 'init', 'my_modify_posts_per_page', 0);
    function my_modify_posts_per_page() {
    	add_filter( 'option_posts_per_page', 'my_option_posts_per_page' );
    }
    function my_option_posts_per_page( $value ) {
    	global $option_posts_per_page;
    	global $option_taxposts_per_page; // your custom posts per page options
    	if ( is_tax( 'mytaxonomy')) {
    		return $option_taxposts_per_page;
    	}
    	else {
    		return $option_posts_per_page;
    	}
    }
  9. nackle2k10
    Member
    Posted 3 years ago #

    the if($option_tax_posts_per_page['blablabla'] is my custom framework option. use your own (forget to change it) :D

  10. nackle2k10
    Member
    Posted 3 years ago #

    the line 3 for the last code block is my own custom framework option. use your own (forget to change it) :D

  11. nackle2k10
    Member
    Posted 3 years ago #

    I don't know if it has to do with the pagination but in my post_type the 'has_archive' is set to true, 'has_archive' => true,

  12. xpert6
    Member
    Posted 3 years ago #

    Wow it works man. Thanks
    I have just removed the exclude_from_search -> true while registering the post type ...... nothing else and it works for me

    Thanks alot for all your help...really appreciated

  13. xpert6
    Member
    Posted 3 years ago #

    Also i have used search_filter function to filter the search ... just like you did

  14. nackle2k10
    Member
    Posted 3 years ago #

    Nice to hear that you also got it fix. Fun with taxonomy then :D

Topic Closed

This topic has been closed to new replies.

About this Topic