• Resolved jwonlineuk

    (@jwonlineuk)


    Hi there,

    What’s the best way to retrieve event metadata (for example, the location map or coordinates) while within the loop? For reference, I’m using the following WP_Query to display future events on my home page, alongside reviews/blog posts underneath:

    <?php $events = array(
    'post_type'      => 'event',
    'meta_query'     => array(
    array(
    	'key'     => '_start_ts',
    	'value'   => current_time('timestamp'),
    	'compare' => '>=',
    	'type'    =>'numeric'
    	)
    ),
    'orderby'        => 'meta_value_num',
    'meta_key'       => '_start_ts',
    'order'          => 'asc',
    );
    $query = new WP_Query( $events ); ?>

    I’d like to be able to get event data while in this loop, but I’m not sure how.

    In the reverse situation, how can I get custom taxonomy information while within the EM_Events::output loop, being formatted by a custom events_list_item_format.php? I have my own custom taxonomy of production company, which I can get within the WP loop using

    <?php echo get_the_term_list( $post->ID, 'company' ); ?>.

    Thanks very much,
    James

    https://www.ads-software.com/plugins/events-manager/

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

    (@angelo_nwl)

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Thanks very much. Doesn’t seem to cover this issue, though.

    Hiya,

    You can use EM_Events::output()
    https://wp-events-plugin.com/documentation/advanced-usage/

    Cheers,
    Phil

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Thanks Phil. Not entirely sure what you mean though. Could you provide an example?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Thanks again, although that doesn’t really help for this issue. I understand how to use EM_Events::output() to get a list of events. I’m not sure how to include custom taxonomy information within that output. What I’d like is a list including WP (rather than EM) categories and tags, as well as my own taxonomy.

    Also, I’d like to know how to display event information, like end time, within a WordPress loop. Is it stored as meta data? If so, will Get_post_meta() work?

    What I’d like is a list including WP (rather than EM) categories and tags, as well as my own taxonomy.

    As normal categories and tags aren’t associated with events that wouldn’t be possible unless you manually added them.

    As for displaying event information, again you should use EM_Event::output(). The normal loop and post meta will not give you the best experience.

    Given all this is custom coding it’s beyond the support we can really offer here though so if you’re struggling you would need to seek the assistance of a developer on this.

    Thanks

    Thread Starter jwonlineuk

    (@jwonlineuk)

    I have added WP tags and categories, as well as my own taxonomy, via register_taxonomy_for_object_type(). These can be displayed very easily while within a WP loop. There must be a fairly simple command to do the same while within the EM_Event::output(), which seems to be a wrapper for a custom WP loop. I just can’t figure it out.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Thanks again, Angelo. Unfortunately none of those tackle this issue.

    I’ve come up with a (pretty ugly) solution for now. As the only way I can access custom taxonomies seems to be with my own WP loop, which means I can’t use EM_Event::output() on my homepage, I’m using:

    em_get_location( $post->_location_id )->location_latitude

    to get the latitude and longitude of event locations from within the loop, and I’m going to feed that into my own link to the Google Maps API.

    If there is a better solution I’d love to hear it. I’m especially interested to know if there is a way to get custom taxonomy information while within an EM_Event::output() loop.

    One of the properties of the EM_Event object which EM_Event::output should give you) is ‘post_id’. You can simply use the value of that property within functions like get_post_meta() or wp_get_post_terms() to retrieve the relevant information outside the Loop.

    Thanks

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Fantastic, thanks very much. Doesn’t seem to be working though. I’ve got a simple <?php echo EM_Events::output( array( 'scope' => 'future' ) ); ?> set up, which is looping correctly through my custom event_list_item_format.php. Using the HTML placeholders I can get most of the event information. Unfortunately, <?php print_r( $EM_Event->post_id ) ?> shows nothing. How do I access the post_id property?

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    $EM_Event->post_id or $EM_Event->ID should work

    I’d guess $EM_Event isn’t correctly instantiated.

    Thread Starter jwonlineuk

    (@jwonlineuk)

    Any ideas on why that might be?

    Thread Starter jwonlineuk

    (@jwonlineuk)

    OK, made some progress and found some odd behaviour.

    $EM_Event->output('#_LOCATIONMAP') works while within the standard WP loop, provided it is called after the_content().

    I still can’t get any response from $EM_Event->post_id, or ID while outputting from EM_Events::output().

    My problem is, at the moment, I can’t do what I’m trying to do with the standard WP loop because I can’t call the_content() before the map while achieving what I’m hoping to. I also can’t use EM_Events::output() because I can’t recall anything from get_post_meta() without access to the post ID.

    Any help would be greatly appreciated!

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Displaying Event metadata within the loop’ is closed to new replies.