自定义帖子类型固定链接返回404 - php

通过浏览支持论坛和博客,我发现除我以外的很少有人在自定义帖子类型和永久链接方面遇到困难。

我的自定义帖子类型(日记)注册正常,并且在管理端看起来都很好。如果在前端搜索,它将显示在搜索结果中。但是,当我单击日记条目时,我得到了404。

我的代码:

register_post_type( 'diary_post',
  array(
    'labels' => array(
      'name' => __( 'Diary Post' ),
      'singular_name' => __( 'Diary Post' ),
      'add_new' => _x('Add New'),
      'add_new_item' => __('Add New Diary Post'),
      'edit_item' => __('Edit Diary Post'),
      'new_item' => __('New Diary Post'),
      'view_item' => __('View Diary Post'),
      'search_items' => __('Search Diary Posts'),
      'not_found' =>  __('No Diary posts found'),
      'not_found_in_trash' => __('No Diary posts found in Trash'), 
      'parent_item_colon' => ''
    ),
    'description' => __( 'Posts to appear on the Diary page' ),
    'public' => true,
    'publicly_queryable' => false,
    'exclude_from_search' => false,
    'query_var' => true,
    'menu_position' => 4,
    'supports' => array('title','editor','author','excerpt','thumbnail', 'custom-fields','comments','trackbacks','revisions'),
    'taxonomies' => array( 'diary_post_type','post_tag'),
    'has_archive' => true,
    'rewrite' => array( 'slug' => 'diary','with_front' => false)
  )
);

我从各种帖子中尝试了以下建议的解决方案,但均未成功:

重新保存我的永久链接
“重写”为“真”两者
'with_front'=> false和
'with_front'=>是添加
flush_rewrite_rules();后
register_post_type
检查是否没有名为“日记”的页面或帖子

即使我尝试通过默认的永久链接结构(例如http://localhost/?diary_post=my-title-here)访问帖子,也没有成功。

我的站点永久链接结构当前为/%year%/%postname%
-将其更改为默认设置也无济于事。

有什么线索吗?机智到此为止。

参考方案

publicly_queryable需要为真,但是如果要设置exclude_from_search,则可能不需要(或public)。参见代码:http://codex.wordpress.org/Function_Reference/register_post_type#Arguments

验证IBAN PHP - php

在设计新平台时,我们尝试集成IBAN编号。我们必须确保IBAN已经过验证,并且存储在数据库中的IBAN始终正确。那么验证数字的正确方法是什么? 参考方案 正如我在其他问题中解释的逻辑一样,我尝试自己创建一个函数。根据Wikipedia文章中解释的逻辑,在下面找到合适的功能。国家特定验证。它适合吗http://en.wikipedia.org/wiki/Int…

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…