Support » Plugin: Events Manager » How to get placeholders data from post metadata / custom fields?

Viewing 11 replies - 1 through 11 (of 11 total)
  • this guy seemed to have the same problem years ago…but no solution was given:
    https://wordpress.org/support/topic/get-all-post-meta/

    EM does not store all of its data as post meta, so you can never get every detail that way. Simple. The only data that EM stores as post_meta are the ones you already listed / found.

    EM Placeholders do not equal post meta. A Placeholder is more like a shortcode – calling a piece of PHP code to echo a dynamic output. The output can be a single integer (like booked spaces) or more than that, like a complete attendees list.

    Placeholders can only be used within the EM_Event Object, EM_Location Object or EM_Booking Object. So, calling a post meta cannot fetch the outcome of a placeholder.

    More information about how placeholders work can be found here:
    https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/

    #_EVENTLINK, for example, is nothing more than a shortcode to echo the url with the event name as linked text referring to the single event in that specific EM_Event Object. Outputting nothing more then:
    <a href="<?php echo get_permalink($EM_Event->post_id); ?>"><?php echo $EM_Event->event_name; ?></a>

    In the case of #_EVENTLINK (because it links to a WP post, equals:
    <a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_name; ?></a>
    But other placeholder work quite differently. πŸ˜‰

    Basically you should see placeholders in a similar way as shortcodes. You can also not get the result of a shortcode through post meta.

    So how can I get the “missing data” (other fields) by post_meta?

    • This reply was modified 1 month, 3 weeks ago by  zerowastefvg.
    Plugin Support timrv

    (@timrv)

    Hello,

    Since some EM data are stored on separate table in database or others are done with some computation. My suggestion is to try the following:

    1. Track the core code of the placeholder and see how EM handles the output and from there you could copy how it is done and change accordingly.

    2. Find the values on Database and make a query.

    I think the 1st suggestion is much easier to do and you could just find the keyword on EM to find the placeholder code.

    So how can I get the β€œmissing data” (other fields) by post_meta?

    Like I tried to explain: you can’t. Not by post_meta, because that info simply is not post meta.

    Tim’s suggestion sounds great and works perfectly if you do any custom coding right in PHP. Then you can get any info you want, because the info is in the database, but not as post meta values.

    Yet it will not work for you, because you want to use it with {cf:_field_name} That is basically a shortcode (or “placeholder” if you will) that only calls the php function get_post_meta( $post_id, '_field_name', true );
    Without custom coding that plugin simply does not search database tables (other than wp_postmeta) for any values.

    So if you really need to use that plugin, you will need to change how that code works to make it fetch other data, not in wp_postmeta.

    @timrv, he wants to use other placeholders (as well), such as #_EVENTLINK. That is not a set value in one of the tables, but a computed outcome. If it only were that easy. LOL. πŸ˜€

    We both know that certain placeholders need to use foreach() loops (like bookings and tickets and attendees), for example. So unless he recreates the static end value/output of every placeholder he wants to use in every single event post as post meta, he will not get that info by using get_post_meta(). That will basically defeat the whole purpose and working of the dynamic EM placeholders. πŸ™‚

    @zerowastefvg, For all purposes, you do not even need #_EVENTLINK. As I already posted, that placeholder links to the Post ID with the Post Name as linked text.

    I am sure WP Telegram has its own way of linking to a post, right? πŸ˜€

    Hello @duisterdenhaag
    I am the author of WP Telegram and I want to help the user solve the issue. Can you please tell me how one can get the Event object from $post object inside save_post callback? One can then use that object to get the event data and pass it to Telegram.

    Thanks to @manzoorwanijk and his great help I could join together all the pieces (so also thanks to all of you) and build the function I needed! πŸ˜€

    add_filter('wptelegram_p2tg_post_data_field_value', function ( $value, $field, $post ) {
    	global $EM_Event;
    	
    	// Set the value according to the field.
    	switch ( $field ) {
                    // creates a new field since the metadata doesn't exists
    		case 'cf:_event_name':
    			// Get the value from EM_Event object
    			$output = $EM_Event->event_name;
    			$output = strtoupper($output);
    			$value = $output;
    			break;
    
                    // modifies on the fly the value of some fields
    		case 'cf:_event_start_time':
    		case 'cf:_event_end_time' :
    			// Get the value from existing metadata
    			$value = date('G:i', strtotime($value));
    			break;
    	}
    
     return $value;
    }, 10, 3 );

    Hope this code could help also somebody else! β™₯

    • This reply was modified 1 month, 3 weeks ago by  zerowastefvg.
    • This reply was modified 1 month, 3 weeks ago by  zerowastefvg.
    • This reply was modified 1 month, 3 weeks ago by  zerowastefvg.

    What I see in that last snippet are still just values that are also in the post_meta.

    These values are all available in ‘normal’ wp_postmeta:
    _event_id = ineger
    _event_timezone = string
    _event_start_time = H:i:s (local)
    _event_end_time = H:i:s (local)
    _event_start = Y-m-d H:i:s (UTC)
    _event_end = Y-m-d H:i:s (UTC)
    _event_start_date = Y-m-d
    _event_end_date = Y-m-d
    _event_start_local = Y-m-d H:i:s (local)
    _event_end_local = Y-m-d H:i:s (local)
    _event_rsvp = 0/1
    _event_rsvp_date = Y-m-d
    _event_rsvp_time = H:i:s (local)
    _event_rsvp_spaces = integer
    _event_spaces = integer
    _location_id = integer

    Any of these fields do not need your custom coding. What that snippet does is merely alter the initial value of the meta_key, like the time format to G:i.
    It does not get you the Location name, Location address, etc.

    $EM_Event contains also other data, I just posted an example easy to understand, you can also use $EM_Location and get all sort of data connected to the event like the address ($EM_Event->location->location_address): when you have the object and you can play with PHP you can do whatever you like. I also needed to manipulate the data output so it solves 2 problems at the same time.

    • This reply was modified 1 month, 3 weeks ago by  zerowastefvg.
Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.