• cfloy

    (@cfloy)


    Hi there!

    I want to add the following event location post meta to the event page: location town, location adress, location title.

    If i check the post meta of an event now I will find ID, start date/end date, the others are missing.

    (I need the post meta on the event page to make a custom form with the Gravity Forms plugin that will show the location title, adress, date, etc.)

Viewing 10 replies - 1 through 10 (of 10 total)
  • joneiseman

    (@joneiseman)

    The Locations are entered separately from the Events in Event Manager. First you add the Location (if it doesn’t already exist). Then when creating an Event you fill in the Location using auto-complete

    The Location can have a title (stored as the post title), and the address, a town, state, and zip code (stored as post meta:, the meta keys are _location_address, _location_town, and _location_state, _location_postcode). The Event post stores the location id as post meta (meta key is _location_id).

    Thread Starter cfloy

    (@cfloy)

    I created multiple locations and then I chose one of the locations in my wordpress builder for the specific event, I do the same with start date + end date.

    But when I look now for the _location_address variable in my Event or Gravity Forms I can’t find it, even though the address will show up when I add this to my HTML: [event] #_LOCATIONADDRESS [/event].
    I did echo the post_meta in my Event but the address, postcode and title won’t show up. ID and start + end date do show up on the other hand.

    When I look for the _location_address variable in my Location Page, it will show up. So it feels like I need to add something to my Events Page?

    • This reply was modified 2 years ago by cfloy.
    joneiseman

    (@joneiseman)

    You can create a Custom Event Field for the location address. You would need to fill out this custom field when creating an event (in the same place where you fill out the Start and End Date). This field would be separate from the Location field that already exists. The custom field could then be referenced like this: #_ATT{Location Address}

    This field would get stored in the post meta and would be accessible in Gravity Forms.

    Thread Starter cfloy

    (@cfloy)

    Thanks so far!

    But isn’t there a smoother solution? I mean all the Location Data must already exist somewhere, no? Since I can output it with the Shortcode/Placeholders (but unfortunately it’s not in my Post Meta) and I already chose the Location in my Event, like I did with the Start and End Date.

    If I use this Custom Event Field Method I need to add the Location twice, when I create an new Event: In the regular field + in the custom field.

    joneiseman

    (@joneiseman)

    Yes, all the data is there but not all of it is stored as post meta of the event post. Some of the data is stored in the post meta of the location post. How are you getting the post meta of the event post in Gravity Forms? Are you using a Gravity Forms Addon?

    Thread Starter cfloy

    (@cfloy)

    I don’t use an Addon. I just add “{custom_field:_event_start_date}” into the field value.
    So I was hoping there is a solution like “{custom_field:_location_title}”

    • This reply was modified 2 years ago by cfloy.
    • This reply was modified 2 years ago by cfloy.
    joneiseman

    (@joneiseman)

    I don’t think there’s a simple solution like that. If I were to try to handle this, I would start with this Addon: https://docs.gravityforms.com/advanced-post-creation-add-on-using-third-party-post-types

    joneiseman

    (@joneiseman)

    If you just want to display the location in read-only mode in gravity forms you could use the “location” post meta (e.g., “{custom_field:location}”).

    Thread Starter cfloy

    (@cfloy)

    Yea, read-only would be fine. But “location” doesnt exist in my post meta. Only the location_id… but that’s no understandable information for the user.

    joneiseman

    (@joneiseman)

    I’m not sure how you associate gravity form entries with event posts but if it is associated with the event post then $entry->post_id should be the post_id for the event. In the following example the form id is 3 and the field id for the location_id is 4 (you would need to change these values to match the form id and field id in your form). The following code snippet should replace the location_id with the location string.

    add_filter( 'gform_entries_field_value', 'modify_entry_values', 10, 4 );
    function modify_entry_values( $value, $form_id, $field_id, $entry ) {
        if ($form_id != 3 || $field_id != 4 || empty( $entry ) || $entry->post_id == 0 || !is_int( $value ) ) {
            return $value;
        }
        $post = get_post( $entry->post_id );
        if ( null === $post )
            return $value;
        $locationId = get_post_meta($post, '_location_id', true);
        if ( empty( $locationId ) )
            return  $value;
    
        $args = array(
            'post_type' => 'location',
            'meta_query' => array(
                'key' => '_location_id',
                'value' => $locationId
            )
        );
        $query = new WP_Query($args);
        if ($query->have_posts()) {
            $query->the_post();
            $location = get_post( get_the_ID() );
            $address = get_post_meta($location, '_location_address', true);
            $town = get_post_meta($location, '_location_town', true);
            $state = get_post_meta($location, '_location_state', true);
            $postcode = get_post_meta($location, '_location_postcode', true);
            $value = $location->post_title . " " . $address . ", " . $town . ", " . $state . " " . $postcode;
        }
        return $value;
    }
    
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Missing Post Meta for Events’ is closed to new replies.