本文介绍了wordpress 3.8.1类别页面2错误404未找到/自定义帖子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先是问题,然后是尝试.

first the problem, then the tries.

问题是,如果我访问除第一类页面之外的其他页面,则会收到404 NOT FOUND错误.在类别页面上,我有正常的分页.第一个站点有效. ( http://mypage.com/category/properties )

The problem is that i get a 404 NOT FOUND error if i visit another page than the first category page.On the category page i have a normal pagination. The first site works. (http://mypage.com/category/properties)

点击下一页"按钮后,我进入的页面是 http://mypage.com/category/properties/page/2 并显示错误404 NOT FOUND.

After i click on the "Next page" button I'm on the page http://mypage.com/category/properties/page/2 and got the error 404 NOT FOUND.

但是为什么?

首先,我尝试了此问题自定义帖子类型和分类法404错误,但是exclude_from_search和下面的查询不起作用.

First I tried this Question Custom Post Type and Taxonomy pagination 404 error, but the exclude_from_search and the queries below doesnt work.

我也尝试过这个. http://wordpress. org/support/topic/一个再次找不到页面的页面但是query_posts try的结果与WP_Query try的结果相同.

I tried this, too. http://wordpress.org/support/topic/one-again-page-not-found-on-second-and-further-pagesBut the query_posts try has the same result as the WP_Query try.

我也尝试过带有预查询的事件.但是问题是一样的-.-

The event with the pre query i tried, too. But the problem is the same -.-

<?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'))
));

结果

第1页

第2页

推荐答案

尝试更改pre_get_posts过滤器.

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' );

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

这篇关于wordpress 3.8.1类别页面2错误404未找到/自定义帖子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 09:37