【发布时间】:2018-08-13 09:06:49
【问题描述】:
与通常使用类别的 Wordpress 博客存档不同,我有一个自定义帖子类型,它使用全局元键和值将这些帖子与我网站中的页面链接。
我想创建一个档案,就像博客上的类别档案一样,但要使用这些元值。
使用自定义 WP 查询并保持分页,同时获得正确的存档 URL 的最佳方法是什么?
function bv_patient_stories_init() {
register_post_type('patient-story', array(
'labels' => array(
'name' => 'Patient Stories',
'singular_name' => 'Patient story',
'add_new' => 'Add new',
'add_new_item' => 'Add a new Patient Story',
'edit_item' => 'Edit Patient Story',
'new_item' => 'New Patient Stories',
'all_items' => 'All Patient Stories',
'view_item' => 'View Patient Story',
'search_items' => 'Search Patient Stories',
'not_found' => 'No Patient Stories have been added',
'not_found_in_trash' => 'No Patient Stories in bin',
'parent_item_colon' => '',
'menu_name' => 'Patient Stories'
),
'description' => 'Patient case study',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'patient-stories', 'with_front' => false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 57,
'supports' => array('title', 'revisions', 'thumbnail', 'excerpt', 'custom-fields', 'comments'),
'menu_icon' => 'dashicons-id',
));
}
【问题讨论】:
-
那么您想创建具有特定元键值的页面吗?比如ass获取所有键值为X的页面?
-
@OrlandoP。不,那不是我想做的。
-
存档不就是这样吗?带有特定类别帖子的页面。在这种情况下,您希望页面上的这些帖子仅具有某些元键值对。
标签: php wordpress custom-post-type archive