Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'save_post', 'ssc_reset_areas_transient' );
- function ssc_get_areas_list(){
- if ( false === ( $areas_data = get_transient( 'areas_of_practice') ) ) {
- ssc_set_areas_transient( );
- $areas_data = get_transient( 'areas_of_practice' );
- }
- return $attorney_data;
- }
- function ssc_set_areas_transient() {
- $nested_posts = array();
- $aop_args = array(
- 'post_type' => 'areas_of_practice',
- 'post_status' => 'publish',
- 'post_parent' => 0,
- 'order_by' => 'menu_order',
- 'order' => 'ASC',
- );
- $the_query = new WP_Query( $aop_args );
- if ( $the_query->have_posts() ) :
- while ( $the_query->have_posts() ) : $the_query->the_post();
- $theparentid = get_the_id();
- $aop_child_args = array(
- 'post_type' => 'areas_of_practice',
- 'post_status' => 'publish',
- 'post_parent' => $theparentid,
- 'order_by' => 'menu_order',
- 'order' => 'ASC',
- );
- $child_posts = array();
- $the_child_query = new WP_Query( $aop_child_args );
- if ( $the_child_query->have_posts() ) :
- while ( $the_child_query->have_posts() ) : $the_child_query->the_post();
- $thechildid = get_the_id();
- $child_posts[] = $thechildid;
- endwhile;
- endif;
- $nested_posts[$theparentid][] = $child_posts;
- endwhile;
- set_transient( 'areas_of_practice', $nested_posts, 52 & WEEK_IN_SECONDS );
- endif;
- wp_reset_query();
- }
- function ssc_reset_areas_transient( $post_id ) {
- delete_transient( 'areas_of_practice' );
- ssc_set_areas_transient();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement