Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // count up function fires on save post
- function count_live_venues( $post_id ) {
- if (get_post_type() == 'venue') {
- // get country info
- $slug = get_the_terms( $post_id , 'country')[0]->slug;
- $term_id = 'country_' . get_the_terms( $post_id, 'country')[0]->term_id;
- // exclude discontinued meta_queery
- $exclude = array(
- 'relation' => 'OR',
- array(
- 'key' => 'venue_discontinued',
- 'compare' => '!=',
- 'value' => true
- ),
- array(
- 'key' => 'venue_discontinued',
- 'compare' => 'NOT EXISTS'
- ),
- );
- // args
- $all_args = array(
- 'post_type' => 'venue',
- 'post_status' => 'publish',
- 'country' => $slug,
- 'posts_per_page' => -1,
- 'meta_query' => $exclude,
- );
- // update 'total_venues' with count of posts
- update_field('field_5c788ae1ec24a', $totalvenues, $term_id);
- }
- }
- // run after ACF saves the $_POST['acf'] data
- add_action('acf/save_post', 'count_live_venues', 20);
- // run whenever trashed / restored
- add_action( 'trashed_post', 'count_live_venues' );
- add_action( 'untrashed_post', 'count_live_venues' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement