仅查询循环内自定义帖子类型的父页面

Cou*_*lin 4 wordpress

我在下面有这个代码来查询帖子和帖子类型:

 <?php
              $args = array('post_type' => 'apartmentlisting', 'parent' => 0, 'showposts'=>'-1');
              query_posts($args);
          ?>
          <?php if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
Run Code Online (Sandbox Code Playgroud)

我正在尝试查询并仅返回父页面,我有10个父页面,每个页面都有大约4-5个子页面.有没有办法让父母回归?

我一直在WP和谷歌上挖掘代码,什么都没有.我只找到了有关页面ID为XX的父级的回帖的文章.

有任何想法吗?

小智 12

如果没有父项,则父项为零.所以你的查询应该有效.但参数是'post_parent'而不是'parent'.并且'showposts'已弃用,请改用"posts_per_page".试试这个:

$args = array('post_type' => 'apartmentlisting', 'post_parent' => 0, 'posts_per_page'=>'-1');
Run Code Online (Sandbox Code Playgroud)