Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. // count up function fires on save post
  2. function count_live_venues( $post_id ) {
  3.  
  4.     if (get_post_type() == 'venue') {
  5.  
  6.         // get country info
  7.         $slug = get_the_terms( $post_id , 'country')[0]->slug;
  8.         $term_id = 'country_' . get_the_terms( $post_id, 'country')[0]->term_id;
  9.  
  10.         // exclude discontinued meta_queery
  11.         $exclude = array(
  12.             'relation' => 'OR',
  13.           array(
  14.               'key'       => 'venue_discontinued',
  15.               'compare'   => '!=',
  16.               'value'     => true
  17.           ),
  18.           array(
  19.               'key'       => 'venue_discontinued',
  20.               'compare'   => 'NOT EXISTS'
  21.           ),
  22.         );
  23.  
  24.         // args
  25.         $all_args = array(
  26.             'post_type'             => 'venue',
  27.             'post_status'           => 'publish',
  28.             'country'               => $slug,
  29.             'posts_per_page'    => -1,
  30.             'meta_query'            => $exclude,
  31.         );
  32.  
  33.    
  34.         // update 'total_venues' with count of posts
  35.         update_field('field_5c788ae1ec24a', $totalvenues, $term_id);
  36.  
  37.     }
  38.  
  39. }
  40.  
  41. // run after ACF saves the $_POST['acf'] data
  42. add_action('acf/save_post', 'count_live_venues', 20);
  43.  
  44. // run whenever trashed / restored
  45. add_action(  'trashed_post',  'count_live_venues' );
  46. add_action(  'untrashed_post',  'count_live_venues' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement