Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test squarecandy ACF events filtering system
<?php
/*
Plugin Name: Test Event Filter
Plugin URI: https://squarecandy.net
Description:
Version: 1.0.0
Author: Square Candy Design
Author URI: http://squarecandydesign.com
Text Domain: squarecandy
*/
// Example - remove fields
add_filter( 'squarecandy_filter_events_fields', 'custom_squarecandy_filter_events_fields', 10, 1 );
function custom_squarecandy_filter_events_fields( $eventfields ) {
// remove unwanted fields
unset( $eventfields['address'] );
unset( $eventfields['city'] );
unset( $eventfields['state'] );
unset( $eventfields['zip'] );
unset( $eventfields['venue_location'] );
unset( $eventfields['zoom_level'] );
return $eventfields;
}
// Example - add fields
add_filter( 'squarecandy_filter_events_fields', 'addnew_squarecandy_filter_events_fields', 10, 1 );
function addnew_squarecandy_filter_events_fields( $eventfields ) {
// add to end
$eventfields['test_new_field_end'] = array(
'key' => 'field_h8f9hwafhdsioahfdso',
'label' => 'Test New Field End',
'name' => 'test_new_field_end',
'type' => 'true_false',
);
// add to middle
$temp_array = array();
$insert_after = 'end_time';
foreach ($eventfields as $key => $value) {
$temp_array[$key] = $value;
if ( $insert_after === $key ) {
$temp_array['test_new_field_middle'] = array(
'key' => 'field_middleh8f9hwaf67234897o',
'label' => 'Test New Field Middle',
'name' => 'test_new_field_middle',
'type' => 'true_false',
);
}
}
$eventfields = $temp_array;
return $eventfields;
}
// Example - change field label
add_filter( 'squarecandy_filter_events_fields', 'relabel_squarecandy_filter_events_fields', 10, 1 );
function relabel_squarecandy_filter_events_fields( $eventfields ) {
// change labels
$eventfields['venue']['label'] = 'Location';
$eventfields['venue_link']['label'] = 'Location Link';
return $eventfields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment