/** * Update the number of gigs at a particular venue. * * @since 1.0.0 */ function update_audiotheme_venue_gig_count($venue_id, $count = 0) { global $wpdb; if (!$count) { $count = get_audiotheme_venue_gig_count($venue_id); } update_post_meta($venue_id, '_audiotheme_gig_count', absint($count)); }
/** * Update a venue's cached gig count when gig is deleted. * * Determines if a venue's gig_count meta field needs to be updated * when a gig is deleted. * * @since 1.0.0 * * @param int $post_id ID of the gig being deleted. */ function audiotheme_gig_before_delete($post_id) { if ('audiotheme_gig' === get_post_type($post_id)) { $gig = get_audiotheme_gig($post_id); if (isset($gig->venue->ID)) { $count = get_audiotheme_venue_gig_count($gig->venue->ID); update_audiotheme_venue_gig_count($gig->venue->ID, --$count); } } }