沃梦达 / 编程问答 / php问题 / 正文

wordpress 3.8.1 类别页面 2 错误 404 未找到/自定义帖子类型

wordpress 3.8.1 category page 2 error 404 not found / custom post type(wordpress 3.8.1 类别页面 2 错误 404 未找到/自定义帖子类型)

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

问题描述

先解决问题,再尝试.

问题

问题是,如果我访问第一个类别页面以外的其他页面,我会收到 404 NOT FOUND 错误.在类别页面上,我有一个正常的分页.第一个站点有效.(

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 category page i have a normal pagination. The first site works. (http://mypage.com/category/properties)

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.

But why?

Tries

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

I tried this, too. http://wordpress.org/support/topic/one-again-page-not-found-on-second-and-further-pages But 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 -.-

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 2

解决方案

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/

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

本文标题为:wordpress 3.8.1 类别页面 2 错误 404 未找到/自定义帖子类型

基础教程推荐