I have created a custom event submission form using Builder. Two items within the form are selecting a calendar and adding an image. Each calendar in the list to choose from is actually a meeting room located within a specific building. I have a specific image of each meeting room that I would like to use for an event scheduled in that room. Is there a way to associate a specific image with a calendar when creating an event by having the user just select the calendar ? I want to eliminate the possibility of the user using the wrong image for the selected calendar.
Open your theme functions.php file and at the bottom add following code:
add_filter('stec_insert_post', function($data) {
if ('stec_event' !== $data['post_type']) { return $data; }
$image_id = false; $calendar_id = (int) $data['meta_input']['calid'];
switch ($calendar_id) {
case 1: $image_id = 101; break; // Sets image with id 101 for calendar with id 1
case 2: $image_id = 102; break; // Sets image with id 102 for calendar with id 2
// etc... }
if ($image_id) { $data['meta_input']['images'] = array_unique(array_merge($data['meta_input']['images'], array($image_id))); }
return $data; });
Just change the values for the image and calendar id numbers.
I have created a custom event submission form using Builder. Two items within the form are selecting a calendar and adding an image. Each calendar in the list to choose from is actually a meeting room located within a specific building. I have a specific image of each meeting room that I would like to use for an event scheduled in that room. Is there a way to associate a specific image with a calendar when creating an event by having the user just select the calendar ? I want to eliminate the possibility of the user using the wrong image for the selected calendar.
Hi,
You can do it via filter.
Open your theme functions.php file and at the bottom add following code:
Just change the values for the image and calendar id numbers.
Stachethemes Developer
Where do I get the image id from ? I would have thought I needed to have a path to the image from the media library ('http://...')
Go to Dashboard -> Media.
In the Media Library click on the image to open Attachment Details popup.
In the browser url you will see .../wp-admin/upload.php?item=229
229 will be your image id number.
Stachethemes Developer