Adding custom fields according to Event Status

Is there a way of adding custom fields to an event based on the status of this event? i.e. Next event, Upcoming events and expired events.

  • Ivan

    Hi there Moringa,

    Thanks for the question and welcome to the WPMU DEV Community!

    I was going through the plugin code to see if there is logic like that applied to the events.
    Unfortunately I wasn't able to find fast solution to give you right now.

    I will mark this to the attention of our SLS(Second Level Support) guys - they are amazing, and should be able to help you with this providing some code snippet.

    Please note that it might take little longer for them to respond.

    Thanks,
    Ivan

  • Vinod Dalvi

    Hi @Moringa,

    If you want to display custom fields values depending on the event status then you can so so by using the code like following.

    <?php
    	$event_id = 2244; // Event ID to get event status from
    	$event_status = get_post_meta( $event_id, 'incsub_event_status', true);
    	if( $event_status == 'open' ){ // Event status check condition
    		// Add here code to dispay custom fields values 
    
    		/*
    		*  display a field value from the current post
    		*/
    
    		the_field( "text_field" );
    	}
    ?>

    You will find more information about display ACF field values on the following pages.

    http://www.advancedcustomfields.com/resources/the_field/
    http://www.advancedcustomfields.com/resources/get_field/
    http://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/

    Please advise if you have more questions.

    Best Regards,
    Vinod Dalvi

  • Moringa

    Hi Guys,

    The above code is not exactly what I meant, as I also wanted to register the status of the event with the ACF.

    ... you want to show those custom fields values only in some cases. Is that correct?

    For example if an event is expired, I want ACF to display a series of fields (in the WP backend) that relate to this status
    If not possible, I can work with the above.

    In addition to this, Is there also a way of having a 'next event' status. Or/and maybe through using the next event shortcode as a hook?

    Currently have:

    <?php
                            $event_id = $event->get_id(); // Event ID to get event status from
                            $event_status = get_post_meta( $event_id, 'incsub_event_status', true);
                            if( $event_status == 'open' ):
                            ?> 
    
                                This event is 'Open' (ticket on sale)
    
                     <?php  elseif ( $event_status == 'closed' ) : ?>
    
                                 This event is closed (it has sold out)
    
                    <?php  elseif ( $event_status == 'archived' ) : ?>
    
                                This event has been archived (do not list this event.)
    
                    <?php  elseif ( $event_status == 'expired' ) : ?>
    
                                This event has expired
    
                    <?php  elseif ( $event_status == 'next_event' ) : ?>
    
                               This is the next event - A way of hooking into this?
    
                     <?php  else : ?>
                                    other condition
    
                        <?php endif; ?>
  • Vinod Dalvi

    Hi @Moringa,

    Thank you for your reply.

    The above code is not exactly what I meant, as I also wanted to register the status of the event with the ACF.

    For example if an event is expired, I want ACF to display a series of fields (in the WP backend) that relate to this status
    If not possible, I can work with the above.

    Can we summarize your above two statements as following?

    You want to create additional custom fields for the Event using ACF which will be different for each event status so for each event status different additional custom fields will be displayed in the admin area on selecting/changing the event status as displayed in the attached screenshot.

    Is the above requirement correct?

    In addition to this, Is there also a way of having a 'next event' status. Or/and maybe through using the next event shortcode as a hook?

    The next event shortcode is not a hook.

    Do you want to create the new event status like "Scheduled Event" which will be for future events as it works with default post?

    If yes then you don't need to create a separate event status for it as you can determine whether the event is scheduled event or not by checking its date and time.

    Please advise.

    Regards,
    Vinod Dalvi

  • Moringa

    Hi Vinod, Thanks again for speedy reply!
    Sorry I realise these are two questions.

    You want to create additional custom fields for the Event using ACF which will be different for each event status so for each event status different additional custom fields will be displayed in the admin area on selecting/changing the event status as displayed in the attached screenshot.

    Is the above requirement correct?

    Yes, correct, is there a way of achieving this?

    Do you want to create the new event status like "Scheduled Event" which will be for future events as it works with default post?

    If you mean a "Scheduled event" to be the first 'Upcoming event'?

    Lets say we have four events; 01-feb, 05-feb, 23-jan ,4-feb.
    I would mean, I would want to be able to display just the 23-jan event using a php query.

    If yes then you don't need to create a separate event status for it as you can determine whether the event is scheduled event or not by checking its date and time.

    How would I be able to do this? I spent a while looking around, but was unable to find any documentation, and my knowledge of php is somewhat limited.

    Thanks again for your help

  • Vinod Dalvi

    Hi @Moringa,

    Yes, correct, is there a way of achieving this?

    You will have to develop custom code to achieve it as described in the following pages.

    http://www.elliotcondon.com/conditional-logic-for-advanced-custom-fields/
    http://wp-types.com/documentation/user-guides/using-custom-fields/#4

    If you are not a programmer then you can consider hiring a developer from https://premium.wpmudev.org/wpmu-custom-development/ to develop it for you.

    Custom code development for custom functionality is beyond the scope of support that we provide. See here : https://premium.wpmudev.org/manuals/using-wpmu-dev/support-vs-custom-development/

    If you mean a "Scheduled event" to be the first 'Upcoming event'?

    No i meant like this http://en.support.wordpress.com/posts/schedule-a-post/

    Lets say we have four events; 01-feb, 05-feb, 23-jan ,4-feb.
    I would mean, I would want to be able to display just the 23-jan event using a php query.

    If you just want to display particular event on the following events listing page then just set the event status of that particular events to open and all others to close.

    http://yoursite.com/events/

    If you want to display it anywhere using custom query then you can do so by developing a custom query using WP_Query class and event custom field incsub_event_status as a parameter as described on the following page.

    http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    How would I be able to do this? I spent a while looking around, but was unable to find any documentation, and my knowledge of php is somewhat limited.

    You can achieve this by using the code like following.

    <?php
    	$event_id = 2307;
    	$start_day = get_post_meta($event_id, 'incsub_event_start', true);
    	$current_date = date('Y-m-d h:i:s', time());
    
    	if(strtotime($start_day) >= strtotime($current_date)){
    	   echo "It's the scheduled event.";
    	} else {
    		echo "The event happened in the past.";
    	}
    ?>

    Thanks,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.