wordpress 3.8.1 category page 2 error 404 not found / custom post type

前端 未结 3 1355
深忆病人
深忆病人 2021-01-14 12:06

first the problem, then the tries.

Problem

The problem is that i get a 404 NOT FOUND error if i visit another page than the first category page. On the cat

相关标签:
3条回答
  • 2021-01-14 12:44

    I had the same problem with my custom post taxonomies pagination. Older posts page was coming with a 404 page not found. This issue is related to WP taxonomy slug so you have to rewrite rules for your custom post type taxonomies like this below:

    function generate_taxonomy_rewrite_rules( $wp_rewrite ) {
    
        $rules = array();
    
        $post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' );
        $taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ), 'objects' );
    
        foreach ( $post_types as $post_type ) {
            $post_type_name = $post_type->name;
            $post_type_slug = $post_type->rewrite['slug'];
    
            foreach ( $taxonomies as $taxonomy ) {
                if ( $taxonomy->object_type[0] == $post_type_name ) {
                    $terms = get_categories( array( 'type' => $post_type_name, 'taxonomy' => $taxonomy->name, 'hide_empty' => 0 ) );
                    foreach ( $terms as $term ) {
                        $rules[$post_type_slug . '/' . $term->slug . '/?$'] = 'index.php?' . $term->taxonomy . '=' . $term->slug;
                        $rules[$post_type_slug . '/' . $term->slug . '/page/?([0-9]{1,})/?$'] = 'index.php?' . $term->taxonomy . '=' . $term->slug . '&paged=' . $wp_rewrite->preg_index( 1 );
                    }
                }
            }
        }
    
        $wp_rewrite->rules = $rules + $wp_rewrite->rules;
    
    }
    
    add_action('generate_rewrite_rules', 'generate_taxonomy_rewrite_rules');
    

    This should work for all custom post type taxonomies and just use your default query loop without passing any arguments. Pages will be generated based on General -> Reading.

    0 讨论(0)
  • 2021-01-14 12:46

    Try change the pre_get_posts filter.

    function namespace_add_custom_types( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
                  'post', 'property'
                ));
        return $query;
       }
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
    

    Found this at http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/

    0 讨论(0)
  • 2021-01-14 12:52

    Try this, it should work.had similar problem

     <?php
            // Display pagination
            global $wp_query;
            $pagination_args = array(
                'base' => '%_%',
                'format' => '?' . $query_string . '&paged=%#%',
                'current' => max(1, get_query_var('paged')),
                'total' => $wp_query->max_num_pages,
                'type' => 'array'
            );
    
            $pagination = paginate_links($pagination_args);
    
    $big = 999999999; // need an unlikely integer
    
    
    $links .= paginate_links(array(
      'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
      'format' => '?' . $query_string . '&paged=%#%&keyword='.$keyword,
      'current' =>max(1, get_query_var('paged')),
      'total' => $wp_query->max_num_pages
    ));
    echo $links;
            ?>
    
    0 讨论(0)
提交回复
热议问题