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

first a problem, then an attempt.

Problem

The problem is that I get a 404 NOT FOUND error if I visit a different page than the first category page. On the category page, I have the usual pagination. The first site is working. ( http://mypage.com/category/properties )

After I click the "Next Page" button, I am on the page http://mypage.com/category/properties/page/2 and received a 404 NOT FOUND error.

But why?

Is trying

At first I tried this question Custom post type and pagination 404 taxonomy , but exclude_from_searchthe queries below do not work either.

I tried it too. http://wordpress.org/support/topic/one-again-page-not-found-on-second-and-further-pages But trying query_posts has the same result as WP_Query.

I also tried an event with a preliminary request. But the problem is the same. -

Example / PHP

<?php

/* /srv/www/mypage/wp-content/themes/twentythirteen/category-1.php */

global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array_merge($wp_query->query, array(
    'posts_per_page' => 4,
    'post_type' => 'property',
    'post_status' => 'publish',
    'meta_key' => 'property_typ',
    'meta_value' => 'Rent',
    'category_name' => null
));

$wp_query = new WP_Query($args);

echo '<ul>';
while (have_posts())
{
    the_post();
    echo '<li><a href="' . get_permalink(get_the_id()) . '">'
         . get_the_title() . '</a></li>';
}
echo '</ul>';

echo paginate_links(array(
    'base' => str_replace(99999, '%#%', esc_url(get_pagenum_link(99999))),
    'total' => $wp_query->max_num_pages,
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged'))
));

results

Page 1

Page 1

Page 2

Page 2

+3
source share
3 answers

Try changing 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/

+2
source

Try this, it should work. 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
source

I had the same problem with my custom posts taxonomy pages. An old message page was not found with 404 pages. This problem is related to the WP taxonomy pool, so you need to rewrite the rules for your custom type taxonomies, as shown 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 type taxonomies and just use the default query loop without passing any arguments. Pages will be created based on General → Reading.

0
source

All Articles