Conditional broadcasting: custom field

This snippet shows how to broadcast a post if a custom field is found.


/**
	@brief		Broadcast a post depending on a postmeta value.
	@since		2018-04-25 07:57:04
**/
function bc_save_post( $post_id )
{
	// To which blogs to broadcast?
	$blogs = [
		57,
		104,
	];
	// The meta key to find
	$meta_key = 'test123';
	// The correct meta value
	$meta_value = 'test321';

	// Don't broadcast if we are already in a broadcast. Otherwise wp_update_post will call the save_post hook...
	if ( ThreeWP_Broadcast()->is_broadcasting() )
		return;

	if ( get_post_meta( $post_id, $meta_key, true ) != $meta_value )
		return;

	ThreeWP_Broadcast()->api()
		->broadcast_children( $post_id, $blogs );
}
add_action( 'save_post', 'bc_save_post' );