WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Query by Location (10 posts)

  1. nevinlaughlin
    Member
    Posted 1 year ago #

    How do I query by the an event in a location? Here's what I have so far

    <?php $my_query = new WP_Query( array( 'post_type' => 'event', 'showposts' => 1 ));
    							while ($my_query->have_posts()) : $my_query->the_post(); ?>

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    you'd want to add a meta search condition for _location_id

  3. nevinlaughlin
    Member
    Posted 1 year ago #

    I added this to the array and it just shows the last event but not in the location I want
    'meta_location_id' => 326

    <?php $my_query = new WP_Query( array( 'post_type' => 'event', 'showposts' => 1, 'meta_location_id' => 326 ));
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

    Thanks!

  4. agelonwl
    Member
    Posted 1 year ago #

    did you try something like $my_query = new WP_Query( array( 'post_type' => 'event', 'showposts' => 1, '_location_id' => 4 ));

  5. nevinlaughlin
    Member
    Posted 1 year ago #

    Thanks for replying, though this is ignoring the _location_id part...just shows the most recent event of all locations

    $my_query = new WP_Query( array( 'post_type' => 'event', 'showposts' => 1, '_location_id' => 4 ));

    Thanks!

  6. agelonwl
    Member
    Posted 1 year ago #

    hi, don't know if this will help you but try this docs - http://wp-events-plugin.com/documentation/advanced-usage/

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    you're doing it wrong, you need to do a (more correctly named) custom field search, as described here - http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

  8. nevinlaughlin
    Member
    Posted 1 year ago #

    nope still doesn't work

    $my_query = new WP_Query( array( 'post_type' => 'event', 'showposts' => 1,
    								'meta_query' => array(
    									array(
    										'key' => '_location_id',
    										'value' => '326'
    									)
    								)
    							));
  9. nevinlaughlin
    Member
    Posted 1 year ago #

    Though this time it doesn't show any events rather than showing an event but not filtered by location.

  10. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    i can't test this myself atm, but it looks right to me. maybe something else is wrong, e.g. wrong location id? or maybe nothing is being output, did you try print_r($my_query)?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags