From f7d4e58c17d78766fc299314b21b4e828eb8a44d Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 19 Jul 2017 15:15:59 -0400 Subject: [PATCH] Redo order for the output Use first query to get main levels in order. Then going through each main level get the sub packages. --- lib/troutcreek-packages.php | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/troutcreek-packages.php b/lib/troutcreek-packages.php index 23537e7..95d1130 100644 --- a/lib/troutcreek-packages.php +++ b/lib/troutcreek-packages.php @@ -143,36 +143,35 @@ function troutcreekPackagesShortcode( $atts ) extract( shortcode_atts( array( 'limit' => '10' ), $atts ) ); ob_start(); global $wp; - //$custom_terms = get_terms( CATEGORY_SLUG ); + // Get all top level posts + $topArgs = array( + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'post_type' => POST_TYPE, + 'post_parent' => 0 + ); + $parentPosts = get_posts( $topArgs ); echo '
'; - //foreach($custom_terms as $custom_term) { + foreach( $parentPosts as $parentPost ) { + //echo '
$parentPost: ' . print_r( $parentPost, true ) . '
'; wp_reset_query(); $args = array( 'posts_per_page' => -1, - 'post_type' => POST_TYPE, - 'orderby' => 'menu_order', - 'order' => 'ASC', - //'tax_query' => array( - //array( - //'taxonomy' => CATEGORY_SLUG, - //'field' => 'slug', - //'terms' => $custom_term->slug, - //), - //), + 'post_type' => POST_TYPE, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'post_parent' => $parentPost->ID ); - $loop = new WP_Query($args); - if($loop->have_posts()) { + $loop = new WP_Query( $args ); + //echo '
$loop: ' . print_r( $loop, true ) . '
'; + if ( $loop->have_posts() ) { echo "
"; - echo "

".$custom_term->name.'

'; + echo '

'.$parentPost->post_title.'

'; echo '
    '; - while($loop->have_posts()) : $loop->the_post(); + while ( $loop->have_posts() ) : $loop->the_post(); // Get the image $thumbnail = get_the_post_thumbnail( null, 'packageList' ); - if ( !$thumbnail ) { - echo '

    ' . get_the_title() . '

    '; - continue; - } // Get the meta data $custom = get_post_custom(); //echo '
    $custom: ' . print_r( $custom, true ) . '
    '; @@ -206,7 +205,7 @@ function troutcreekPackagesShortcode( $atts ) echo '
'; } - //} + } echo '
'; $output = ob_get_contents(); ob_end_clean(); -- 2.17.1