admin管理员组文章数量:1130349
I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
Share Improve this question edited Jan 10, 2019 at 8:52 Glorfindel 6113 gold badges10 silver badges18 bronze badges asked Feb 7, 2013 at 9:25 KayoKayo 1831 silver badge9 bronze badges 02 Answers
Reset to default 2By default page post type doesn't support category taxonomy. But you can easily fix it by register category taxonomy for page post type:
add_action( 'init', 'wpse8170_init' );
function wpse8170_init() {
register_taxonomy_for_object_type( 'category', 'page' );
}
Now you will see categories meta box in the same place as you see it at post creation page.
To get page's categories just call wp_get_post_categories function like this (thanks to @Subharanjan):
$page_categories = wp_get_post_categories( get_the_ID() );
$page_categories = wp_get_post_categories( get_the_ID() );
Pass the current page id/ any pageid as the param and get the asociated categories.
I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
Share Improve this question edited Jan 10, 2019 at 8:52 Glorfindel 6113 gold badges10 silver badges18 bronze badges asked Feb 7, 2013 at 9:25 KayoKayo 1831 silver badge9 bronze badges 02 Answers
Reset to default 2By default page post type doesn't support category taxonomy. But you can easily fix it by register category taxonomy for page post type:
add_action( 'init', 'wpse8170_init' );
function wpse8170_init() {
register_taxonomy_for_object_type( 'category', 'page' );
}
Now you will see categories meta box in the same place as you see it at post creation page.
To get page's categories just call wp_get_post_categories function like this (thanks to @Subharanjan):
$page_categories = wp_get_post_categories( get_the_ID() );
$page_categories = wp_get_post_categories( get_the_ID() );
Pass the current page id/ any pageid as the param and get the asociated categories.
本文标签: loopHow to insert category list into post creation pageand retrieve chosen categories
版权声明:本文标题:loop - How to insert category list into post creation page, and retrieve chosen categories? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749026400a2305175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论