Title: wp_query issue
Last modified: August 31, 2016

---

# wp_query issue

 *  Resolved [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/)
 * Hi,
 * Thanks for your help with this plugin. I am really confused. I am building a 
   custom query, but i am not able to filter by event owner.
 * Here is the code i am working with:
 * <?php
    $loop = new WP_Query( array( ‘post_type’ => ‘event’, ‘meta_key’ => ‘event_owner’,‘
   meta_value’ => 1, ‘posts_per_page’ => 10 ) ); ?>
 * <?php
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
 * FYI – If i omit meta_key’ => ‘event_owner’, ‘meta_value’ => 1 the loop works 
   just fine. Any idea why that is?
 * Many thanks,
    Yvan
 * [https://wordpress.org/plugins/events-manager/](https://wordpress.org/plugins/events-manager/)

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/wp_query-issue/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_query-issue/page/2/?output_format=md)

 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139271)
 * Fyi – I have also tried the following and it still won’t work.
 * $loop = new WP_Query( array( ‘post_type’ => ‘event’, ‘posts_per_page’ => 100 ,
   ‘
   meta_query’ => array( array( ‘key’ => ‘event_owner’, ‘value’ => 1, ‘compare’ 
   => ‘IN’ ) ) )
 * );
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139390)
 * here’s another thread which may help you with this – [https://wordpress.org/support/topic/em-with-wp_query-and-orderby-date?replies=15](https://wordpress.org/support/topic/em-with-wp_query-and-orderby-date?replies=15)
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139401)
 * Hi,
 * I have tried all the example you have sent and nothing seems to work. Here is
   the code i am working with. Could you please let me know what i am doing wrong.
   I am sure it is something simple … but i am stuck right now:
 * <?php
    $loop = new WP_Query( array( ‘post_type’ => ‘event’, ‘posts_per_page’ 
   => 100 , ‘meta_query’ => array( ‘key’ => ‘event_owner’, ‘value’ => 1, ‘compare’
   => ‘=’ ) ) ); ?>
 * <?php
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
 * <?php
    global $post; $EM_Event = em_get_event($post->ID, ‘post_id’);
 * $latitude = $EM_Event->get_location()->location_latitude;
    $longitude = $EM_Event-
   >get_location()->location_longitude; $date = $EM_Event->event_end_date; $start_time
   = $EM_Event->event_start_time; $attendees = $EM_Event->event_rsvp_spaces; $attributes
   = $EM_Event->event_attributes; $attributes_string = implode (‘/’ , $attributes);
   echo $termsString; ?>
 * Again, everything works well except the WP_query … any chance you guys can help
   out. I really love the plugin and looking to launch soon …
 * Many thanks,
    Yvan
 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139437)
 * What WordPress called _authors_, Events Manager calls_ Event Owner_s. In both
   cases, they’re WordPress user accounts. So you need to search / filter on the
   ID of the user you want to look for.
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139448)
 * Hi,
 * Thanks so much for the tip. I have tweaked the code a bit, but the page is not
   loading … i think i am getting closer, but there must be something wrong. Any
   idea?
 *     ```
       <?php 
   
       global $post;
       $EM_queries = em_get_event($post->ID, 'post_id');
   
       $eventslug = $EM_queries->get_event_slug()->event_slug;
   
       $loop = new WP_Query( array ('post_type' => 'event',  'posts_per_page' => -1 ,
       	'meta_query'             => array(
       		array(
       			'key'       => '$eventslug',
       			'value'     => 'test-fitler-1',
       			'compare'   => '=',
   
       		),
       	),
       ));
   
       ?>
       ```
   
 * Thanks again for all your help!
 * Best,
    Yvan
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139455)
 * BTW – I realized that if i changed ‘post_per_page’ => 100 to ‘post_per_page’ 
   => 0 it has no effect on the output of my loop. I am really struggling with this.
   Any help would be most welcome. I have gone through everything … Codex, forums,
   stackoverflow … nothing helped …
 * Thanks,
    yvan
 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139463)
 * What output is your code generating?
 * The key line should be without the single quotes around it because it’s a variable:
 * `'key' => $eventslug,`
 * That could be the problem.
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139464)
 * No, that won’t work either. So here is my problem. I don’t understand why i can’t
   just use things like ‘event_slug’ => ‘example1’ in my query? What do i need to
   do to access the custom fields i see in the wp_em_events table? I would just 
   like to query for any field in that table (event_slug, etc). Could you please
   explain to me why this isn’t straight forward and how one could access and filter
   by these fields.
 * Also, would upgrading to pro allow me to get more feedback from you guys?
 * Many thanks,
    Yvan
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139469)
 * maybe you can try to use global $wpdb if you want to query the events table
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139473)
 * Hi,
 * I am still not sure how that would help. Would you guys be able to provide me
   with mroe support if i were to upgrade to pro?
 * Many thanks,
    Yvan
 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139474)
 * Sorry, custom coding is outside of the Pro support policy.
 * What output are you getting with that code?
 * Did you try my suggestion?
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139475)
 * Hi,
 * This isn’t working … and i am really lost … I don’t understand why i am not able
   to just query events by custom field like so:
 *     ```
       <?php $loop = new WP_Query( array( 'post_type' => 'event', 'posts_per_page' => 100 ,
       'meta_query' => array(
   
       			'key' => 'event_owner',
       			'value' => 1,
       			'compare' => '='
   
       		)
       	)
       ); ?>
   
       <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       ```
   
 * Every tutorial i have seen is using this syntax so I don’t understand why querying
   events with events-manager would be anything different. What am I not getting…
   please help me … i am really stuck and really need this work :((
 * Many thanks,
    Yvan
 *  [Stephen](https://wordpress.org/support/users/idiots_guide/)
 * (@idiots_guide)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139478)
 * Try this
 *     ```
       <?php
       global $post;
       $EM_queries = em_get_event($post->ID, 'post_id');
       $eventslug = $EM_queries->event_slug;
       $args = array (
       	'post_type' => 'event',
       	'posts_per_page' => -1,
       	'meta_query' => array(
       		array(
       			'key' => '$eventslug',
       			'value' => 'test-fitler-1',
       			'compare' => '=',
       		),
       	)
       );
       $EM_Events = EM_Events::get( $args );
       $events_count = EM_Events::count( $args );
       ?>
       <?php get_header(); ?>
       <?php echo 'Total events: ' . $events_count; ?>
       <?php get_footer(); ?>
       ```
   
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139480)
 * Thanks Stephen,
 * I am going to play with this and see where it leads me. I will keep you posted.
   REALLY REALLY appreciate your help on this .
 * Thanks!
 * Best,
    Yvan
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/#post-7139482)
 * Hi,
 * So at first i thought this worked as it returned the right value (1), but then
   i realized $event_count would echo 1 no matter which key and value I chose. FYI–
   Here is the code i am using. Any thoughts?
 *     ```
       <?php
       global $post;
       $EM_queries = em_get_event($post->ID, 'post_id');
       $eventslug = $EM_queries->event_id;
       $args = array (
       	'post_type' => 'event',
       	'posts_per_page' => 100,
       	'meta_query' => array(
       		array(
       			'key' => '$eventslug',
       			'value' => 48,
       			'compare' => '=',
       		),
       	)
       );
       $EM_Events = EM_Events::get( $args );
       $events_count = EM_Events::count( $args );
       ?>
   
       <?php get_header(); ?>
       <?php echo 'Total events: ' . $EM_Events; ?>
       <?php echo 'Total events: ' . $events_count; ?>
       <?php get_footer(); ?>
       ```
   
 * Many thanks,
    Yvan

Viewing 15 replies - 1 through 15 (of 21 total)

1 [2](https://wordpress.org/support/topic/wp_query-issue/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_query-issue/page/2/?output_format=md)

The topic ‘wp_query issue’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 21 replies
 * 4 participants
 * Last reply from: [Ynasr](https://wordpress.org/support/users/ynasr/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139518)
 * Status: resolved