Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. function ssc_set_areas_transient() {
  2.  $nested_posts = array();
  3.  $aop_args = array(
  4.    'post_type' => 'areas_of_practice',
  5.    'post_status' => 'publish',
  6.    'post_parent' => 0,
  7.    'order_by' => 'menu_order',
  8.    'order' => 'ASC',
  9.  );
  10.  $the_query = new WP_Query( $aop_args );
  11.  if ( $the_query->have_posts() ) :
  12.    while ( $the_query->have_posts() ) : $the_query->the_post();
  13.      $theparentid = get_the_id();
  14.  
  15.      $aop_child_args = array(
  16.        'post_type' => 'areas_of_practice',
  17.        'post_status' => 'publish',
  18.        'post_parent' => $theparentid,
  19.        'order_by' => 'menu_order',
  20.        'order' => 'ASC',
  21.      );
  22.      $child_posts = array();
  23.      $the_child_query = new WP_Query( $aop_child_args );
  24.      if ( $the_child_query->have_posts() ) :
  25.        while ( $the_child_query->have_posts() ) : $the_child_query->the_post();
  26.          $thechildid = get_the_id();
  27.          $child_posts = $thechildid;
  28.      endwhile;
  29.       print '<pre>';
  30.       print_r ( $child_posts );
  31.       print '</pre>';
  32.    endif;
  33.    $nested_posts[$theparentid][] = $child_posts;
  34.    endwhile;
  35.    print '<pre>';
  36.    print_r ( $nested_posts );
  37.    print '</pre>';
  38.    set_transient( 'areas_of_practice', $nested_posts, 52 & WEEK_IN_SECONDS );
  39.  endif;
  40.  wp_reset_query();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement