Query to get child pages of current page and display it in action hook

First I want to apologize if there are spelling mistakes in this question.

I'm using Genesis Framework.

According to the following answer:

https://wordpress.stackexchange.com/a/60295/146574

I'm trying to display that loop in single-$cpt.php, the loop works fine. But when I try to display in other places through an action hook (genesis_after_entry in my case) the loop contains all cpts, but I want to display only child posts of the current post.

Here is the code:

?php

$args = array(
    'post_type'      = 'curso',
    'posts_per_page' = -1,
    'post_parent'    = $post-ID,
    'order'          = 'ASC',
    'orderby'        = 'menu_order'
 ); 

$parent = new WP_Query( $args );

?

ul class="parent-page"

?php if ( $parent-have_posts() ) : ?
    ?php while ( $parent-have_posts() ) : $parent-the_post(); ?    
    lia href="?php the_permalink(); ?" title="?php the_title(); ?"?php the_title(); ?/a/li
    ?php endwhile; ?

?php endif; wp_reset_postdata(); ?
/ul
?php

genesis();

I would be very grateful if anybody can help me. Thanks.

Topic loop child-pages genesis-theme-framework custom-post-types Wordpress

Category Web


I was making a beginner's mistake. I was not defining the global variable post. I publish my complete code for the community. May be useful for something like me.

<?php

add_action( 'genesis_after_entry', 'capitulos_curso' );
function capitulos_curso(){
global $post;          
$args = array(
    'post_type'      => 'curso',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 ); 

$parent = new WP_Query( $args );

?>

<?php if ( $parent->have_posts() ) : ?>
    <ul class="parent-page">    
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>    
        <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    </ul>
    <?php endwhile; ?>

<?php endif; wp_reset_postdata();} ?>
<?php
genesis();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.