admin管理员组文章数量:1410717
I've created custom post type "Services" with 'hierarchical' => true,
. My loop is simple:
while (have_posts()) {
the_post();
get_template_part('content', get_post_type());
}
In admin I have next structure:
- Service 1
- Service 2
- Sub-service
The problem is that on Services page I have all of them. But I want only 1 level posts without children posts. And children posts should be inside parent post. How can I do that?
I've created custom post type "Services" with 'hierarchical' => true,
. My loop is simple:
while (have_posts()) {
the_post();
get_template_part('content', get_post_type());
}
In admin I have next structure:
- Service 1
- Service 2
- Sub-service
The problem is that on Services page I have all of them. But I want only 1 level posts without children posts. And children posts should be inside parent post. How can I do that?
Share Improve this question asked Oct 30, 2017 at 7:39 aciderntacidernt 1113 bronze badges1 Answer
Reset to default 0please add your Custom post type name here 'post_type' => 'Services', // required
<?php
$args=array(
'post_parent' => 0, // required
'post_type' => 'Services', // required
'orderby' => 'menu_order', // to display according to hierarchy
'order' => 'ASC', // to display according to hierarchy
'posts_per_page' => -1, // to display all because default is 10
);
$query = null;
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while($query->have_posts()) {
$query->the_post();
$post_id=get_the_ID();
$post=get_post($post_id,'ARRAY_A');
echo $post['ID'].': '.$post['post_title'].'<br>';
}
}
wp_reset_query($query);
?>
本文标签: Custom post type loop without children
版权声明:本文标题:Custom post type loop without children 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745014724a2637767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论