admin管理员组

文章数量:1302268

Im trying this to show My CurrentPage (Licenciatura en Ciencias del Arte y Gestión Cultural.) child called "Infraestructura" by it's slug. I don't know whats wrong with my code. It Returns No PAGE. My guess is that pagename is not working...

        <?php   

        $pageid = $post->ID;
        $arg1 = array(
                'post_type'      => 'page',
                'posts_per_page' => 1,
                'post_parent'    => $pageid,
                'pagename' => 'infraestructura',
                
             );
        $child = new WP_Query( $arg1 ); ?>
        <div class="wrapp">
            <?php echo $pageid; ?>
                <?php if ($child->have_posts()) :?>
                <?php while ($child->have_posts()) : $child->the_post(); ?>
                    <?php the_title(); ?>
                    <?php the_content(); ?>
                <?php endwhile; ?>
            <?php else: ?>
                no page
            <?php endif; wp_reset_postdata();  ?>
        </div>

this is my page

NOTE: I have the same structure with multiple pages, this is WHY I need the SLUG or name to work

Im trying this to show My CurrentPage (Licenciatura en Ciencias del Arte y Gestión Cultural.) child called "Infraestructura" by it's slug. I don't know whats wrong with my code. It Returns No PAGE. My guess is that pagename is not working...

        <?php   

        $pageid = $post->ID;
        $arg1 = array(
                'post_type'      => 'page',
                'posts_per_page' => 1,
                'post_parent'    => $pageid,
                'pagename' => 'infraestructura',
                
             );
        $child = new WP_Query( $arg1 ); ?>
        <div class="wrapp">
            <?php echo $pageid; ?>
                <?php if ($child->have_posts()) :?>
                <?php while ($child->have_posts()) : $child->the_post(); ?>
                    <?php the_title(); ?>
                    <?php the_content(); ?>
                <?php endwhile; ?>
            <?php else: ?>
                no page
            <?php endif; wp_reset_postdata();  ?>
        </div>

this is my page

NOTE: I have the same structure with multiple pages, this is WHY I need the SLUG or name to work

Share Improve this question edited Mar 19, 2021 at 22:08 May Ornelas asked Mar 19, 2021 at 22:02 May OrnelasMay Ornelas 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

this is how i solved my problem:

<?php   

        $pageid = $post->ID;
        $pageslug = $post->post_name;
        $pos = $post->post_parent;
        $posname = get_post_field( 'post_name', $pos );;
        
        $arg1 = array(
                'post_type'      => 'page',
                'posts_per_page' => 1,
                'pagename' => $posname.'/'.$pageslug.'/infraestructura',
                
             );
        $child = new WP_Query( $arg1 ); ?>
        <div class="wrapp">
                <?php if ($child->have_posts()) :?>
                <?php while ($child->have_posts()) : $child->the_post(); ?>
                    <?php the_title(); ?>
                    <?php the_content(); ?>
                <?php endwhile; ?>
            <?php else: ?>
                no page
            <?php endif; wp_reset_postdata();  ?>
        </div>

本文标签: wp queryShow child by slugwhile knowing parent ID