Advertisement
Guest User

Make it transient

a guest
Jul 1st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  add_action( 'save_post', 'ssc_reset_areas_transient' );
  3.  function ssc_get_areas_list(){
  4.   if ( false === ( $areas_data = get_transient( 'areas_of_practice') ) ) {
  5.     ssc_set_areas_transient( );
  6.     $areas_data = get_transient( 'areas_of_practice' );
  7.   }
  8.   return $attorney_data;
  9. }
  10.  function ssc_set_areas_transient() {
  11.   $nested_posts = array();
  12.   $aop_args = array(
  13.     'post_type' => 'areas_of_practice',
  14.     'post_status' => 'publish',
  15.     'post_parent' => 0,
  16.     'order_by' => 'menu_order',
  17.     'order' => 'ASC',
  18.   );
  19.   $the_query = new WP_Query( $aop_args );
  20.   if ( $the_query->have_posts() ) :
  21.     while ( $the_query->have_posts() ) : $the_query->the_post();
  22.       $theparentid = get_the_id();
  23.      
  24.       $aop_child_args = array(
  25.         'post_type' => 'areas_of_practice',
  26.         'post_status' => 'publish',
  27.         'post_parent' => $theparentid,
  28.         'order_by' => 'menu_order',
  29.         'order' => 'ASC',
  30.       );
  31.       $child_posts = array();
  32.       $the_child_query = new WP_Query( $aop_child_args );
  33.       if ( $the_child_query->have_posts() ) :
  34.         while ( $the_child_query->have_posts() ) : $the_child_query->the_post();
  35.           $thechildid = get_the_id();
  36.           $child_posts[] = $thechildid;
  37.       endwhile;
  38.     endif;
  39.     $nested_posts[$theparentid][] = $child_posts;
  40.     endwhile;
  41.     set_transient( 'areas_of_practice', $nested_posts, 52 & WEEK_IN_SECONDS );
  42.   endif;
  43.   wp_reset_query();
  44. }  
  45. function ssc_reset_areas_transient( $post_id ) {
  46.   delete_transient( 'areas_of_practice' );
  47.   ssc_set_areas_transient();
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement