自定义帖子类型的Wordpress永久链接问题,仅在我登录时才有效

时间:2014-08-08 17:46:53

标签: php wordpress custom-post-type permalinks

我把头发拉出来,希望有人可以提供帮助。我创建了一个自定义帖子类型 - 事件

add_action('init', 'event'); // Events post-type
function event()
{
    register_taxonomy_for_object_type('category', 'event');
    register_taxonomy_for_object_type('post_tag', 'event');
    register_post_type('event',
        array(
        'labels' => array(
         'name' => __('Events', 'event'),
         'singular_name' => __('Event', 'event'),
         'add_new' => __('Add New', 'event'),
         'add_new_item' => __('Add New Event', 'event'),
         'edit' => __('Edit', 'event'),
         'edit_item' => __('Edit Event', 'event'),
         'new_item' => __('New Event', 'event'),
         'view' => __('View Event', 'event'),
         'view_item' => __('View Event', 'event'),
         'search_items' => __('Search Event', 'event'),
         'not_found' => __('No Events found', 'event'),
         'not_found_in_trash' => __('No Events found in Trash', 'event')
     ),
        'public' => true,
        'publicly_queryable' => true,
        'hierarchical' => true,
     'has_archive' => true,
     'supports' => array(
         'title',
         'editor',
         'excerpt',
         'thumbnail'
     ),
        'taxonomies' => array(
         'post_tag',
         'category'
     ) // Add Category and Post Tags support
 ));
}

Events.php 模板文件中,对于“事件”页面,我使用以下方式查询帖子类型:

<?php query_posts('post_type=event&order=ASC&post_status=future'); ?>

<?php if (have_posts()): while (have_posts()) : the_post(); ?>

<li>
    <a href="<?php the_permalink(); ?>">    
        ...
    </a>
</li>

<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>

当然还有 single-event.php

所以,如果我在浏览器中登录到wordpress,我可以到单个事件页面没问题。但是如果我退出了,他们会返回404页面,以及我尝试打开它们的任何其他计算机。 我没有运行缓存软件,每次调整后都访问了Permalinks页面,.htaccess文件看起来很好。

有什么想法吗?

4 个答案:

答案 0 :(得分:1)

在您的Events.php模板中,您有:

var bindingId = "123"; var newValue = [["123","123","123"], ["123","123","123"], ["123","123","123"]]; return Excel.run(function (ctx) { var binding = ctx.workbook.bindings.getItem(bindingId); var range = binding.getRange().load('values, address'); return ctx.sync().then(function () { range.values = newValue; return ctx.sync(); }); });

<?php query_posts('post_type=event&order=ASC&post_status=future'); ?>设置为&#34; post_status&#34;,因此只有在您登录后才会看到这些帖子。如果您已退出,即使他们 发布,你也不会看到他们,除非他们的发布日期早于您查看活动的日期。

答案 1 :(得分:0)

尝试致电:

flush_rewrite_rules();

后:

register_post_type('event',
    array(
    'labels' => array(
     'name' => __('Events', 'event'),
     'singular_name' => __('Event', 'event'),
     'add_new' => __('Add New', 'event'),
     'add_new_item' => __('Add New Event', 'event'),
     'edit' => __('Edit', 'event'),
     'edit_item' => __('Edit Event', 'event'),
     'new_item' => __('New Event', 'event'),
     'view' => __('View Event', 'event'),
     'view_item' => __('View Event', 'event'),
     'search_items' => __('Search Event', 'event'),
     'not_found' => __('No Events found', 'event'),
     'not_found_in_trash' => __('No Events found in Trash', 'event')
 ),
    'public' => true,
    'publicly_queryable' => true,
    'hierarchical' => true,
 'has_archive' => true,
 'supports' => array(
     'title',
     'editor',
     'excerpt',
     'thumbnail'
 ),
    'taxonomies' => array(
     'post_tag',
     'category'
 ) // Add Category and Post Tags support
));

或者将其添加到arguments数组中:

'rewrite' => array( 'slug' => 'event','with_front' => FALSE),

所以你最终得到:

register_post_type('event',
    array(
    'labels' => array(
     'name' => __('Events', 'event'),
     'singular_name' => __('Event', 'event'),
     'add_new' => __('Add New', 'event'),
     'add_new_item' => __('Add New Event', 'event'),
     'edit' => __('Edit', 'event'),
     'edit_item' => __('Edit Event', 'event'),
     'new_item' => __('New Event', 'event'),
     'view' => __('View Event', 'event'),
     'view_item' => __('View Event', 'event'),
     'search_items' => __('Search Event', 'event'),
     'not_found' => __('No Events found', 'event'),
     'not_found_in_trash' => __('No Events found in Trash', 'event')
 ),
    'public' => true,
    'publicly_queryable' => true,
    'hierarchical' => true,
 'has_archive' => true,
 'supports' => array(
     'title',
     'editor',
     'excerpt',
     'thumbnail'
 ),
    'taxonomies' => array(
     'post_tag',
     'category'
 ),
'rewrite' => array( 'slug' => 'event','with_front' => FALSE),
));

答案 2 :(得分:0)

register_post_type有几个论据,我认为这些论点可能有所不同。尝试其中一些:

'public' => true, // Master 
    'publicly_queryable' => false, // must be set to true to use in a template
    'exclude_from_search' => true,
    'show_in_nav_menus' => false,
    'show_in_admin_bar' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite'   => array( 'slug' => 'custom_type', 'with_front' => false ), 
    'has_archive' => 'custom_type',
    'capability_type' => 'post',
    'hierarchical' => false,

答案 3 :(得分:0)

您是否检查了帖子状态? 如果邮寄了eveent帖子,则只有登录用户才能访问该页面。否则他们可以看到404页。