查询的页面而不是自定义分类

时间:2011-03-21 作者:fuxia

当我尝试获取自定义分类法的存档时,WP会搜索一个页面,但没有找到任何内容。

设置功能中的“我的代码”。php:

add_action( \'init\', \'register_store_taxonomy\' );

function register_store_taxonomy()
{
    $args = array (
        \'hierarchical\'      => TRUE
    ,   \'label\'             => \'Store\'
    ,   \'public\'            => TRUE
    ,   \'query_var\'         => \'store\'
    ,   \'rewrite\'           => TRUE
    ,   \'show_in_nav_menus\' => TRUE
    ,   \'show_ui\'           => TRUE
    );
    register_taxonomy(
            \'store\'
        ,   array ( \'post\', \'page\' )
        ,   $args
        );
}
现在我有一个贴着商店标签的帖子itunes. 单击指向的链接/store/mac-store/ 应列出此分类中的所有帖子。确实如此!在本地服务器(Win7)上
但是,在登台服务器(Debian的设置基本相同)上,我得到了404页面(和404状态标题)。

没有具有类似名称或slug的页面,甚至在垃圾箱中也没有。我已经刷新了permalinks好几次了。没有活动插件。我试过谷歌,但找不到任何有用的东西。

调试我在函数中添加了以下代码。php跟踪错误:

add_action( \'wp_footer\', \'dump_query\' );
function dump_query()
{
    if ( current_user_can( \'edit_posts\' ) )
    {
        pre_dump( $GLOBALS[\'wp_query\'] );
    }
}

function pre_dump( $var, $print = TRUE )
{
    $out = \'<pre class="vardump">\' . htmlspecialchars( var_export( $var, TRUE ) ) . \'</pre>\';

    if ( ! $print )
        return $out;

    print $out;
}
输出本地工作查询

WP_Query::__set_state(array(
   \'query_vars\' => 
  array (
    \'store\' => \'itunes\',
    \'error\' => \'\',
    \'m\' => 0,
    \'p\' => 0,
    \'post_parent\' => \'\',
    \'subpost\' => \'\',
    \'subpost_id\' => \'\',
    \'attachment\' => \'\',
    \'attachment_id\' => 0,
    \'name\' => \'\',
    \'static\' => \'\',
    \'pagename\' => \'\',
    \'page_id\' => 0,
    \'second\' => \'\',
    \'minute\' => \'\',
    \'hour\' => \'\',
    \'day\' => 0,
    \'monthnum\' => 0,
    \'year\' => 0,
    \'w\' => 0,
    \'category_name\' => \'\',
    \'tag\' => \'\',
    \'cat\' => \'\',
    \'tag_id\' => \'\',
    \'author_name\' => \'\',
    \'feed\' => \'\',
    \'tb\' => \'\',
    \'paged\' => 0,
    \'comments_popup\' => \'\',
    \'meta_key\' => \'\',
    \'meta_value\' => \'\',
    \'preview\' => \'\',
    \'s\' => \'\',
    \'sentence\' => \'\',
    \'fields\' => \'\',
    \'category__in\' => 
    array (
    ),
    \'category__not_in\' => 
    array (
    ),
    \'category__and\' => 
    array (
    ),
    \'post__in\' => 
    array (
    ),
    \'post__not_in\' => 
    array (
    ),
    \'tag__in\' => 
    array (
    ),
    \'tag__not_in\' => 
    array (
    ),
    \'tag__and\' => 
    array (
    ),
    \'tag_slug__in\' => 
    array (
    ),
    \'tag_slug__and\' => 
    array (
    ),
    \'meta_query\' => 
    array (
    ),
    \'ignore_sticky_posts\' => false,
    \'suppress_filters\' => false,
    \'cache_results\' => true,
    \'update_post_term_cache\' => true,
    \'update_post_meta_cache\' => true,
    \'post_type\' => \'\',
    \'posts_per_page\' => 10,
    \'nopaging\' => false,
    \'comments_per_page\' => \'50\',
    \'no_found_rows\' => false,
    \'taxonomy\' => \'store\',
    \'term\' => \'itunes\',
    \'order\' => \'DESC\',
    \'orderby\' => \'wp_posts.post_date DESC\',
  ),
   \'tax_query\' => 
  WP_Tax_Query::__set_state(array(
     \'queries\' => 
    array (
      0 => 
      array (
        \'taxonomy\' => \'store\',
        \'terms\' => 
        array (
          0 => \'itunes\',
        ),
        \'include_children\' => true,
        \'field\' => \'slug\',
        \'operator\' => \'IN\',
      ),
    ),
     \'relation\' => \'AND\',
  )),
   \'post_count\' => 1,
   \'current_post\' => -1,
   \'in_the_loop\' => false,
   \'comment_count\' => 0,
   \'current_comment\' => -1,
   \'found_posts\' => \'1\',
   \'max_num_pages\' => 1,
   \'max_num_comment_pages\' => 0,
   \'is_single\' => false,
   \'is_preview\' => false,
   \'is_page\' => false,
   \'is_archive\' => true,
   \'is_date\' => false,
   \'is_year\' => false,
   \'is_month\' => false,
   \'is_day\' => false,
   \'is_time\' => false,
   \'is_author\' => false,
   \'is_category\' => false,
   \'is_tag\' => false,
   \'is_tax\' => true,
   \'is_search\' => false,
   \'is_feed\' => false,
   \'is_comment_feed\' => false,
   \'is_trackback\' => false,
   \'is_home\' => false,
   \'is_404\' => false,
   \'is_comments_popup\' => false,
   \'is_paged\' => false,
   \'is_admin\' => false,
   \'is_attachment\' => false,
   \'is_singular\' => false,
   \'is_robots\' => false,
   \'is_posts_page\' => false,
   \'is_post_type_archive\' => false,
   \'parsed_tax_query\' => true,
   \'query\' => 
  array (
    \'store\' => \'itunes\',
  ),
   \'request\' => \' SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND ( wp_term_relationships.term_taxonomy_id IN (135,134,133,132,131,130,129,128,125) ) AND wp_posts.post_type IN (\\\'post\\\', \\\'page\\\', \\\'attachment\\\') AND (wp_posts.post_status = \\\'publish\\\' OR wp_posts.post_author = 7 AND wp_posts.post_status = \\\'private\\\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10\',
   \'posts\' => 
  array ( /* cut out */),
   \'queried_object\' => 
  stdClass::__set_state(array(
     \'term_id\' => \'124\',
     \'name\' => \'iTunes\',
     \'slug\' => \'itunes\',
     \'term_group\' => \'0\',
     \'term_taxonomy_id\' => \'125\',
     \'taxonomy\' => \'store\',
     \'description\' => \'\',
     \'parent\' => \'0\',
     \'count\' => \'1\',
  )),
   \'queried_object_id\' => 124,
))
输出暂存服务器,断开的查询
WP_Query::__set_state(array(
   \'query_vars\' => 
  array (
    \'page\' => 0,
    \'pagename\' => \'itunes\',
    \'error\' => \'\',
    \'m\' => 0,
    \'p\' => 0,
    \'post_parent\' => \'\',
    \'subpost\' => \'\',
    \'subpost_id\' => \'\',
    \'attachment\' => \'\',
    \'attachment_id\' => 0,
    \'name\' => \'itunes\',
    \'static\' => \'\',
    \'page_id\' => 0,
    \'second\' => \'\',
    \'minute\' => \'\',
    \'hour\' => \'\',
    \'day\' => 0,
    \'monthnum\' => 0,
    \'year\' => 0,
    \'w\' => 0,
    \'category_name\' => \'\',
    \'tag\' => \'\',
    \'cat\' => \'\',
    \'tag_id\' => \'\',
    \'author_name\' => \'\',
    \'feed\' => \'\',
    \'tb\' => \'\',
    \'paged\' => 0,
    \'comments_popup\' => \'\',
    \'meta_key\' => \'\',
    \'meta_value\' => \'\',
    \'preview\' => \'\',
    \'s\' => \'\',
    \'sentence\' => \'\',
    \'fields\' => \'\',
    \'category__in\' => 
    array (
    ),
    \'category__not_in\' => 
    array (
    ),
    \'category__and\' => 
    array (
    ),
    \'post__in\' => 
    array (
    ),
    \'post__not_in\' => 
    array (
    ),
    \'tag__in\' => 
    array (
    ),
    \'tag__not_in\' => 
    array (
    ),
    \'tag__and\' => 
    array (
    ),
    \'tag_slug__in\' => 
    array (
    ),
    \'tag_slug__and\' => 
    array (
    ),
    \'ignore_sticky_posts\' => false,
    \'suppress_filters\' => false,
    \'cache_results\' => true,
    \'update_post_term_cache\' => true,
    \'update_post_meta_cache\' => true,
    \'post_type\' => \'\',
    \'posts_per_page\' => 10,
    \'nopaging\' => false,
    \'comments_per_page\' => \'50\',
    \'no_found_rows\' => false,
    \'order\' => \'DESC\',
    \'orderby\' => \'wp_posts.post_date DESC\',
  ),
   \'tax_query\' => 
  WP_Tax_Query::__set_state(array(
     \'queries\' => 
    array (
    ),
     \'relation\' => \'AND\',
  )),
   \'post_count\' => 0,
   \'current_post\' => -1,
   \'in_the_loop\' => false,
   \'comment_count\' => 0,
   \'current_comment\' => -1,
   \'found_posts\' => 0,
   \'max_num_pages\' => 0,
   \'max_num_comment_pages\' => 0,
   \'is_single\' => false,
   \'is_preview\' => false,
   \'is_page\' => false,
   \'is_archive\' => false,
   \'is_date\' => false,
   \'is_year\' => false,
   \'is_month\' => false,
   \'is_day\' => false,
   \'is_time\' => false,
   \'is_author\' => false,
   \'is_category\' => false,
   \'is_tag\' => false,
   \'is_tax\' => false,
   \'is_search\' => false,
   \'is_feed\' => false,
   \'is_comment_feed\' => false,
   \'is_trackback\' => false,
   \'is_home\' => false,
   \'is_404\' => true,
   \'is_comments_popup\' => false,
   \'is_paged\' => false,
   \'is_admin\' => false,
   \'is_attachment\' => false,
   \'is_singular\' => false,
   \'is_robots\' => false,
   \'is_posts_page\' => false,
   \'is_post_type_archive\' => false,
   \'parsed_tax_query\' => true,
   \'query\' => 
  array (
    \'page\' => \'\',
    \'pagename\' => \'store/itunes\',
  ),
   \'request\' => \' SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (wp_posts.ID = \\\'0\\\') AND wp_posts.post_type = \\\'page\\\'  ORDER BY wp_posts.post_date DESC \',
   \'posts\' => 
  array (
  ),
   \'queried_object\' => NULL,
   \'queried_object_id\' => 0,
))
我觉得我错过了一些显而易见的东西,但我现在迷路了。

所以我的问题是:如何让WP搜索分类法归档?为什么它可以在一台服务器上工作,而不能在另一台服务器上工作?

更新永久链接设置为/%year%/%postname%/ 在两台服务器上,我刷新了init 发件人:

$GLOBALS[\'wp_rewrite\']->flush_rules();
使用更新2Rewrite Analyzer plugin 从@Jan Fabry开始,我比较了本地安装和临时服务器上的规则。对于后者,没有相关规则。

重写本地规则

store/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$            store: ([^/]+)
           feed: (feed|rdf|rss|rss2|atom)
store/([^/]+)/(feed|rdf|rss|rss2|atom)/?$             store: ([^/]+)
           feed: (feed|rdf|rss|rss2|atom)
store/([^/]+)/page/?([0-9]{1,})/?$            store: ([^/]+)
          paged: ([0-9]{1,})
store/([^/]+)/?$              store: ([^/]+)
我真的必须手动添加规则吗?通常register_taxonomy() 应该这样做,不是吗?

解决方法

呸!我使用了一种变通方法来为每个函数添加缺少的重写规则。php:

add_action( \'init\', \'add_taxrules_manually\' );
function add_taxrules_manually()
{
    $tax           = \'store\';
    $rewrite_rules = get_option( \'rewrite_rules\' );

    if ( isset ( $rewrite_rules[ $tax . \'/([^/]+)/?$\' ] ) )
    {
        return;
    }

    $new_rules = array (
        $tax . \'/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$\' => \'index.php?\' . $tax . \'=$matches[1]&feed=$matches[2]\',
        $tax . \'/([^/]+)/(feed|rdf|rss|rss2|atom)/?$\'      => \'index.php?\' . $tax . \'=$matches[1]&feed=$matches[2]\',
        $tax . \'/([^/]+)/page/?([0-9]{1,})/?$\'             => \'index.php?\' . $tax . \'=$matches[1]&paged=$matches[2]\',
        $tax . \'/([^/]+)/?$\'                               => \'index.php?\' . $tax . \'=$matches[1]\',
    );

    $update = array_merge( $new_rules, $rewrite_rules );
    update_option( \'rewrite_rules\', $update );
}
Important: 新规则必须在页面规则之前。更改中参数的顺序array_merge() 不会修复它。

这个问题仍然悬而未决,因为我只是想了解这里发生了什么。

1 个回复
最合适的回答,由SO网友:scribu 整理而成

你刷新了重写规则了吗?

结束

相关推荐

custom taxonomies on pages

我需要一些帮助如何在所选页面上显示自定义分类?我的意思是我有3个自定义分类法位置、持续时间和;coursesi已经创建了三个页面,我想在其中显示这些自定义分类法的术语,我已经使用函数在我的帖子中显示了这些术语<?php echo do_shortcode(\"[terms]\"); ?> 但同样的事情我也想在我的页面上显示,我怎么能做到呢??????