Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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

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 如何获取当前自定义帖子的子帖子并按自定义域编号排序?_Php_Wordpress_Wordpress Theming_Parent Child - Fatal编程技术网

Php 如何获取当前自定义帖子的子帖子并按自定义域编号排序?

Php 如何获取当前自定义帖子的子帖子并按自定义域编号排序?,php,wordpress,wordpress-theming,parent-child,Php,Wordpress,Wordpress Theming,Parent Child,我有自定义的帖子类型“cars”,它的子帖子类型是“carvariants” 我想做的是获取当前帖子(cars)的子帖子(carvariants)。我尝试了以下代码: <div> <?php $parent_id = 1064; $the_query = new WP_Query(array( 'post_parent' => $parent_id, 'post_type' => 'carvarian

我有自定义的帖子类型“cars”,它的子帖子类型是“carvariants”

我想做的是获取当前帖子(cars)的子帖子(carvariants)。我尝试了以下代码:

    <div>
    <?php 
    $parent_id = 1064;
    $the_query = new WP_Query(array(
'post_parent' => $parent_id,
        'post_type'         => 'carvariants',
        'posts_per_page'    => 1,
        'meta_key'          => 'wpcf-minimum-price',
        'orderby'           => 'meta_value_num',
        'order'             => 'ASC'
    ));

    ?>
    <?php if( $the_query->have_posts() ): ?>
        <ul>
        <?php while( $the_query->have_posts() ) : $the_query->the_post(); 
                $compprd = get_the_ID(); ?>

  <?php the_title(); ?>
     <?php
         endwhile; ?>
        </ul>
    <?php endif; ?>
    <?php wp_reset_query();  ?>
    </div>


我想按自定义字段wpcf最低价格显示汽车订单的子帖子
但“后家长”不起作用。此代码显示空白输出。这有什么问题吗?

我没试过。但我希望这能奏效

如果它不起作用,请给我留言,我会尽力让它起作用

此外,如果有更好的解决方案,我将很高兴看到专业人士提供的代码:

<div>
    <?php 
    $parent_id = 1064;
    $args = array( 'child_of' => $parent_id );

    $children_pages = get_pages( $args );

    if ( count( $children_pages ) != 0 ) :
        foreach ( $children_pages as $children_page ) :
            if ( $children_page->have_posts() ) :
                    $args_for_posts = array( 'posts_per_page' => 1,
                        'post_type' => 'carvariants',
                        'orderby' => 'meta_value_num',
                        'order' => 'ASC',
                        'post_parent' => $children_page );
                    $postlist = get_posts( $args_for_posts );
                    foreach ( $postlist as $post) :
                        setup_postdata( $post ); ?>
                        <ul>
                            <?php
                            the_post();
                            ?>
                        </ul>    
                    <?php
                    endforeach;
                    wp_reset_postdata();
            endif;
        endforeach;
    else : ?>
        <p>No content to show.</p>
    <?php 
    endif; ?>
</div>

没有内容显示


当问题陈述只是“它不起作用”时,很难提供解决方案。请你的问题更完整地描述一下你预期会发生什么,以及这与实际结果有什么不同。请参阅,以获取关于什么是好的解释的提示。我想按自定义字段wpcf最低价格显示汽车订单的子帖子,但“post\u parent”不起作用。此代码显示空白输出。这有什么不对劲吗?谢谢你的回复,但我看不出有什么内容要展示。消息