wordpress 3.8.1 category page 2 error 404 not found / custom post type(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 未找到/自定义帖子类型
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01