SHOW:
|
|
- or go back to the newest paste.
| 1 | - | <?php |
| 1 | + | <?php |
| 2 | - | $aop_args = array( |
| 2 | + | add_action( 'save_post', 'ssc_reset_areas_transient' ); |
| 3 | - | 'post_type' => 'areas_of_practice', |
| 3 | + | function ssc_get_areas_list(){
|
| 4 | - | 'post_status' => 'publish', |
| 4 | + | if ( false === ( $areas_data = get_transient( 'areas_of_practice') ) ) {
|
| 5 | - | 'post_parent' => 0, |
| 5 | + | ssc_set_areas_transient( ); |
| 6 | - | 'order_by' => 'menu_order', |
| 6 | + | $areas_data = get_transient( 'areas_of_practice' ); |
| 7 | - | 'order' => 'ASC', |
| 7 | + | } |
| 8 | - | ); |
| 8 | + | return $attorney_data; |
| 9 | - | $the_query = new WP_Query( $aop_args ); |
| 9 | + | } |
| 10 | - | if ( $the_query->have_posts() ) : |
| 10 | + | function ssc_set_areas_transient() {
|
| 11 | - | while ( $the_query->have_posts() ) : $the_query->the_post(); ?> |
| 11 | + | $nested_posts = array(); |
| 12 | - | <li class="parent_aop"> |
| 12 | + | $aop_args = array( |
| 13 | - | <a class="parent-wrapper" href="<?php the_permalink(); ?>"> |
| 13 | + | 'post_type' => 'areas_of_practice', |
| 14 | - | <?php |
| 14 | + | 'post_status' => 'publish', |
| 15 | - | if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
|
| 15 | + | 'post_parent' => 0, |
| 16 | - | the_post_thumbnail('medium');
|
| 16 | + | 'order_by' => 'menu_order', |
| 17 | - | } ?> |
| 17 | + | 'order' => 'ASC', |
| 18 | - | <span><?php the_title(); ?></span> |
| 18 | + | ); |
| 19 | - | </a> |
| 19 | + | $the_query = new WP_Query( $aop_args ); |
| 20 | - | <ul class="child_list"> |
| 20 | + | if ( $the_query->have_posts() ) : |
| 21 | - | <?php |
| 21 | + | while ( $the_query->have_posts() ) : $the_query->the_post(); |
| 22 | - | $theparentid = get_the_id(); |
| 22 | + | $theparentid = get_the_id(); |
| 23 | - | //echo $theparentid; |
| 23 | + | |
| 24 | - | |
| 24 | + | $aop_child_args = array( |
| 25 | - | $aop_child_args = array( |
| 25 | + | 'post_type' => 'areas_of_practice', |
| 26 | - | 'post_type' => 'areas_of_practice', |
| 26 | + | 'post_status' => 'publish', |
| 27 | - | 'post_status' => 'publish', |
| 27 | + | 'post_parent' => $theparentid, |
| 28 | - | 'post_parent' => $theparentid, |
| 28 | + | 'order_by' => 'menu_order', |
| 29 | - | 'order_by' => 'menu_order', |
| 29 | + | 'order' => 'ASC', |
| 30 | - | 'order' => 'ASC', |
| 30 | + | ); |
| 31 | - | ); |
| 31 | + | $child_posts = array(); |
| 32 | - | |
| 32 | + | $the_child_query = new WP_Query( $aop_child_args ); |
| 33 | - | $the_child_query = new WP_Query( $aop_child_args ); |
| 33 | + | if ( $the_child_query->have_posts() ) : |
| 34 | - | if ( $the_child_query->have_posts() ) : |
| 34 | + | while ( $the_child_query->have_posts() ) : $the_child_query->the_post(); |
| 35 | - | while ( $the_child_query->have_posts() ) : $the_child_query->the_post(); ?> |
| 35 | + | $thechildid = get_the_id(); |
| 36 | - | <li class="child_aop"> |
| 36 | + | $child_posts[] = $thechildid; |
| 37 | - | <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> |
| 37 | + | endwhile; |
| 38 | - | </li> |
| 38 | + | endif; |
| 39 | - | <?php |
| 39 | + | $nested_posts[$theparentid][] = $child_posts; |
| 40 | - | $thechildid = get_the_id(); |
| 40 | + | endwhile; |
| 41 | - | //echo $thechildid; |
| 41 | + | set_transient( 'areas_of_practice', $nested_posts, 52 & WEEK_IN_SECONDS ); |
| 42 | - | endwhile; |
| 42 | + | endif; |
| 43 | - | endif; |
| 43 | + | wp_reset_query(); |
| 44 | - | ?> |
| 44 | + | } |
| 45 | - | </ul> |
| 45 | + | function ssc_reset_areas_transient( $post_id ) {
|
| 46 | - | </li> |
| 46 | + | delete_transient( 'areas_of_practice' ); |
| 47 | - | <?php |
| 47 | + | ssc_set_areas_transient(); |
| 48 | - | endwhile; |
| 48 | + | } |
| 49 | - | endif; |
| 49 | + | ?> |