Tricky one. I have a client with custom post type - products Products are in structure:

  1. A
    • a1
    • a2
    • a3
  2. B
    • b1
    • b2
    • b3

On parent page A and B I have a meta-field where client can set if show the page with it childrens at home page.

<?php 
        global $post;
        $args=array(
        'post_type' => 'products',
        'meta_key' => 'pakmenuposition',
        'meta_compare' => '=',
         'meta_value' => 'frontside'
        );
        $pages = get_posts($args);

        if ($pages) {
         $pageids = array();
         foreach ($pages as $page) {
        $pageids[]= $page->ID;
             }
            }

        wp_list_pages( 'post_type=products&include='.implode(",", $pageids) ); 
        ?> 

I can not figure out, how to append the list to variable $pageids of all child pages from parent. I dont want to oblige client to go in to every child product and set its meta value to frontside=true.

If you have an idea, please, help me.

UPDATE

This is what I found as a solution:

<?php 
                    global $post;
                    $args=array(
                      'post_type' => 'products',
                      'meta_key' => 'pakmenuposition',
                      'meta_compare' => '=',
                      'meta_value' => 'frontside'
                    );
                    $pages = get_posts($args);

                    if ($pages) {
                      $pageids = array();
                      foreach ($pages as $page) {
                        $pageids[]= $page->ID;
                      }
                    }
                    $childs = get_posts('post_type=products&post_parent='.implode(",", $pageids));
                    if ($childs) {
                      $childids = array();
                      foreach ($childs as $child) {
                        $childids[]= $child->ID;
                      }
                    }
            wp_list_pages('title_li=&post_type=products&include='.implode(",", $pageids).','.implode(",", $childids) ); 
                    ?>
link|improve this question

60% accept rate
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.