Do not show child pages within a file page
-
16-04-2021 - |
题
I have a CPT created, in my CPT file page the father pages and daughter pages are shown.
Books of science
Book 1
Book 2
Books of science fiction
Book 1
Book 2
In my case I don't want it to be like that, since I want to show the daughter pages only inside the father page.
How can I make the page file only show the father pages and not the daughters?
This is my CPT file template currently:
<?php
//* Force full-width-content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
remove_action('genesis_loop', 'genesis_do_loop');
//* New loop
add_action('genesis_loop', 'b_custom_loop');
function b_custom_loop() {
global $wp_query;
$args = array(
'post_type' => 'b_books',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => 10
);
genesis_custom_loop( $args );
}
Is that possible?
解决方案
Your can use post_parent
parameter for your query.
Ref: https://codex.wordpress.org/Class_Reference/WP_Query
This will change your query to:
$args = array(
'post_type' => 'b_books',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => 10,
'post_parent' => 0
);
genesis_custom_loop( $args );