最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - Do not show child pages within a file page

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Jun 14, 2019 at 11:26 Marifer Villarroel asked Jun 14, 2019 at 10:56 Marifer VillarroelMarifer Villarroel 276 bronze badges 2
  • You're going to need to share the code you're using to display what you already have. – Jacob Peattie Commented Jun 14, 2019 at 11:00
  • Hi Jacob, I just updated my question. – Marifer Villarroel Commented Jun 14, 2019 at 11:26
Add a comment  | 

1 Answer 1

Reset to default 0

Your can use post_parent parameter for your query. Ref: https://codex.wordpress/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 );
发布评论

评论列表(0)

  1. 暂无评论