首页 > 解决方案 > WP - 检索当前页面的子页面

问题描述

我有一些依赖于合作伙伴 CPT 的 cpt 帖子。我想从当前父 cpt 检索子 cpt,但此代码检索 cpt 中的所有页面(其他父和子也是)。怎么了?

if (is_singular('conversacion-ingles')) {
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop',  'show_all_children');


    function show_all_children(){

        $child_args = array(
            'post_parent' => $post->ID, // The parent id.
            'post_type'   => 'conversacion-ingles',
            'post_status' => 'publish',
            'order'       => 'ASC'
        );

        $children = get_children( $child_args );
        if ( empty($children) ) return;


        echo '<div class="children">';
        echo '<ul class="children level-'.$current_level.'-children">';

        foreach ($children as $child) {

            echo '<li>';

            echo '<a href="'.get_permalink($child->ID).'">';
            echo get_the_title($child->ID);
            echo '</a>';

            echo '</li>';

            }

        echo '</ul>';
        echo '</div>';
    } 
}

标签: phpwordpress

解决方案


推荐阅读