• Resolved mshaidulatov

    (@mshaidulatov)


    Hi,

    We use Advanced Custom Fields to add new fields to events. We use templates to return these data on event pages like #_ATT(custom_field_name). It works fine. The issue we face is inability to change date format returned by EM for these fields. basicly we can change it standard fields in EM like start date but unable to do the same for ACF fields. Is there anyway to do that?
    Thanks, Marat

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    hi,

    sorry for the confusion but you created your custom fields using ACF or EM ? By default, you can update custom attributes bu updating your events.

    Thread Starter mshaidulatov

    (@mshaidulatov)

    Hi and thanks for prompt answer.

    We created custom fields using ACF because It seems to be fastest way to do that without interrupting core code of EM. We use names of these fields in EM templates to get values. It works just fine but format of dates could not be corrected.
    I.e. values of these custom fields are returned in following format: Y-M-dd while we need to return in European format like dd-M-Y. Hope it makes sense. Is there any way to fix this issue? We would prefer to avoid changes in core EM files for these minor change. Otherwise, it works great.
    Thanks, Marat

    p.s. we have found if it is possible to add datepicker fields with custom fields created through EM.

    • This reply was modified 5 years, 3 months ago by mshaidulatov.

    Hello,

    If you used ACF to create the fields. You could try using their shortcode to display the details. Here is a link of their shortcode on how to do it: https://www.advancedcustomfields.com/resources/shortcode/

    Thread Starter mshaidulatov

    (@mshaidulatov)

    Do you mean to use shortcode within EM template? Or you suggest theme template and include shortcodes from ACF or EM? I dont get it, sorry.

    Hi @mshaidulatov,
    EM user here too. Let me see if I understand you correctly…
    You’ve created custom fields using ACF and want to use them in the front-end with Em’s #_ATT{}. Right?

    without interrupting core code of EM

    You are only touching the core code if you edit a core php file. ??

    All date fields are always saved to the database in the international technical notation: Y-m-d.

    Calling a post meta value with #_ATT{field_name} (in EM) is exactly the same as using {cf:field_name} (in ACF). They both fetch the static value of the post meta key. So if it’s saved as Y-d-m, it will be outputted as Y-m-d.

    Events Manager is extremely flexible and allows to manipulate just about every output. The pure magic of: Custom Placeholders. ??
    https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/

    You will need to create a new placeholder for each your custom fields you wish to manipulate/change.

    For example, the ACF date field saved “date of birth” as field name “date_of_birth” in the default Y-m-d format. Then this would be your custom placeholder code:

    function em_change_acf_date_format($replacement, $EM_Event, $result) {
    	global $EM_Event;
    	if( $result === "#_DATEOFBIRTH" ) {
    		// Fetch the original field value from the database.
    		$original = $EM_Event->output("#_ATT{date_of_birth}");
    		// Convert the date to the saved date format in your EM Settings.
    		$replacement = date_i18n( get_option('dbem_date_format'), strtotime( $original ) );
    	}
    	return $replacement;
    }
    add_filter('em_event_output_placeholder', 'em_change_acf_date_format', 10, 3);

    Then within EM you can simply call #_DATEOFBIRTH instead of #_ATT{date_of_birth} to echo the altered output.

    Thread Starter mshaidulatov

    (@mshaidulatov)

    Hi Patrick, you are correct. It is perfect solution. I appreciate that you did for me. Just tried with almost no changes and it worked like a charm. Thanks a lot! Thumbs up.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to update date format returned by #_ATT?’ is closed to new replies.