[英]Wordpress Permalink issue with Custom Post Type, only works if I'm logged in
我正在拔頭發,希望有人能幫忙。 我創建了一個自定義帖子類型事件 。
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頁以及我嘗試打開它們的任何其他計算機。 我沒有運行任何緩存軟件,每次調整后我都訪問了“永久鏈接”頁面,並且.htaccess文件看起來不錯。
有任何想法嗎?
在Events.php模板中,您具有:
<?php query_posts('post_type=event&order=ASC&post_status=future'); ?>
post_status
設置為“ future
”,因此,只有在您登錄后,您才能看到這些帖子。如果您已注銷,則即使發布它們也看不到它們,除非它們的發布日期早於您正在查看活動的日期。
嘗試致電:
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),
));
我看不到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,
您檢查過帖子狀態了嗎? 如果該事件發布是計划發布,則只有登錄用戶才能訪問該頁面。 否則他們會看到404頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.