Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress循环中仅返回父级_Php_Wordpress_Loops - Fatal编程技术网

Php 在wordpress循环中仅返回父级

Php 在wordpress循环中仅返回父级,php,wordpress,loops,Php,Wordpress,Loops,我在我的wordpress主题中使用了一个自定义的帖子类型,我需要关于循环的帮助。这是我的密码: <?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10 ) ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <li>

我在我的wordpress主题中使用了一个自定义的帖子类型,我需要关于循环的帮助。这是我的密码:

<?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10 ) ); ?>
     <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
         <li>
             <?php the_post_thumbnail( 'magazine' ); ?>
             <h2><?php the_title( ); ?></h2>
             <?php the_content;?>
         </li>
     <?php endwhile; ?>


  • 这将返回自定义字段“杂志”中的10篇最新文章。我希望它只显示自定义字段“杂志”中的家长。与页面一样,“我的自定义字段”也有属性,因此您可以选择层次结构(父/子)。我想编辑循环,这样它只返回父母(杂志的最新一期,而不是每期中的文章),有人知道如何使用上面的wordpress循环吗?

    只需将
    'post\u parent'=>0
    添加到args数组中即可

    <?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10, 'post_parent' => 0 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
         <li>
             <?php the_post_thumbnail( 'magazine' ); ?>
             <h2><?php the_title( ); ?></h2>
             <?php the_content;?>
         </li>
    <?php endwhile; ?>
    
    
    

  • 如果你只想要孩子,那么反过来又如何呢?这要困难得多。您可以添加一个自定义WHERE语句,检查post_父字段是否大于0,但除此之外,我想不出任何东西。您是希望所有子帖子都指向所有父帖子,还是仅针对单个帖子的子帖子?