• Resolved uc55

    (@uc55)


    I have been doing an extensive amount of research just to find this answer and can’t seem to find it anywhere. The plugin states that you can get all of the custom field’s with get_post_meta() however I have not found a list of keys for the fields in the events.

    My goal is to display the custom field of City, State and Country that you fill out in the event page when setting you location. I so far have this but with the Name and Date field.

    <?php
            $args = array(
                'post_type' => 'event',
                'posts_per_page' => 5
                );
            $query = new WP_Query( $args );
            ?>
    
            <?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
    
            <?php $id = $query->post->ID; ?>
    
            <h1>Event Name: <?php echo get_the_title($id); ?></h1>
    
            <h1>Date:<?php echo get_post_meta($id, '_event_start_date', true); ?></h1>
    
            <h1>City: <?php echo get_post_meta($id, 'NEED KEY!!', true); ?></h1> <!--Need a key for the City-->
    
            <h1>State: </h1><!--Need a key for the State-->
    
            <h1>Country: </h1><!--Need a key for the Country-->
    
            <?php endwhile;
            wp_reset_postdata();
            else : ?>
    
            <h1>You have no events, please add an event.</h1>
    
            <?php endif; ?>

    As you can see it’s within a WP_Query loop and it prints out all of the events “Event Name” and “Date” because I have the correct KEY for those in the get_post_meta() function. The only reason I have those to pieces of date is because I found it in some code but cant seem to find anything else about displaying the individual fields in the events within a loop.

    I need the proper key to use with get_post_meta() to retrieve that specific field from everything iv read. But I cannot seem to find a list of keys for the life of me. Can someone help me print out thee pieces of data from the Events within a loop please.

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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How can I get the location fields with get_post_meta?’ is closed to new replies.