Getting child content

I am using the folowing to get child title and content. Each child has a gallery and a short code in the content editor in the content, but I only get the gallery and not shortcode. It isn’t something to do with the short code but rather on the content as I tried to add some paragraph to the content after the gallery and it does not show up.

<?php $pages = get_pages('child_of='.$page->ID.'&sort_order=asc&number=3&sort_column=menu_order&parent='.$page->ID);
foreach($pages as $page) {
    $content = $page->post_content;
    $content = apply_filters('the_content', $content);
?>

    <div class="span4">
       <h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
        <?php echo $content ?>
    </div>

I think $content = apply_filters('the_content', $content); is basically stripping out part of the content

Read More

Any idea why the shortcode isn’t showing?

Related posts

Leave a Reply

2 comments

  1. I would like to suggest you to use WP_Query to fetch pages from db:

    $the_query = new WP_Query( array( 
        'post_parent'    => $page->ID,
        'orderby'        => 'menu_order',
        'order'          => 'ASC',
        'posts_per_page' => 3,
    ) );
    
    while ( $the_query->have_posts() ) :
        $the_query->the_post();
    
        ?>
        <div class="span4">
            <h2><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
            <?php the_content() ?>
        </div>
        <?php
    endwhile;
    
    wp_reset_postdata();
    

    Also be careful! You use $page variable at first line of your snippet as already defined, and then you re declare it again when you use it in the foreach loop at the 2nd line of your snippet.

  2. This is how i resolved it:

       <?php
     /*
     Template Name: home
    */
     get_header(); ?>
    
    <?php $counter = 1 ?>
     <div class="row-fluid"> 
         <?php
        $args = array(
    'child_of' => 4,
    'parent' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
     ); 
     $childrens = query_posts('showposts=3&post_parent=4&post_type=page&orderby=menu_order&order=DESC');
    
     foreach ( $childrens as $children ) :
    query_posts('showposts=3&post_parent='.$children->ID.'&post_type=page&orderby=menu_order&order=DESC');
    if ( have_posts ) :
        while ( have_posts() ) : the_post();
    ?>
            <div class="span4">
                <h2>
                    <?php the_title(); ?>
                </h2>
                <?php the_content(); ?>
            </div>
    <? if ($counter % 3 == 0): ?>
    <div id="content" class="row-fluid"></div>
    </div>
    <div class="row-fluid">
        <?php endif; ?>
    <?php $counter++; ?>
    <?php
        endwhile;
    endif;
        endforeach;
    ?>
    </div>
    
    <?php get_footer(); ?>