Title: wp_query issue
Last modified: August 31, 2016

---

# wp_query issue

 *  Resolved [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 5 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 6 replies - 16 through 21 (of 21 total)

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

 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139490)
 * sorry I’m afraid that we can’t help with custom coding 100% as per the support
   policy – [http://eventsmanagerpro.com/support-policy/](http://eventsmanagerpro.com/support-policy/)
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139493)
 * Hi,
 * I totally understand. That said, all I am trying to do is understand why events
   custom field are not accessible and why all the fixes you suggested aren’t working.
 * Many thanks,
    Yvan
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139504)
 * Hi,
 * Is anyone able to assist me with this? I am really struggling to understand why
   querying events created by events-manager would be any different from querying
   any other custom posts. I am not looking for custom code, but for an explanation
   of why that is and ideas on how to solve this issue.
 * I am pretty sure this is something lots users are trying to achieve and so it’s
   probably worth addressing …
 * Many thanks,
    Yvan
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139507)
 * Hi,
 * So i am now using the following code and here everything work.
 *     ```
       <?php
   
       $events = EM_Events::get(array( 'limit'=>10, 'owner' => 0, 'pagination'=>1));
       foreach ( $events as $event ) {
       	echo $event->event_owner;
       	}
   
       ?>
       ```
   
 * The problem is that i then need to loop through events using `<?php while ( $
   events->have_posts() ) : $events->the_post(); ?>`
 * Can anyone help me out with this?
 * Many thanks,
    yvan
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139508)
 *  Thread Starter [Ynasr](https://wordpress.org/support/users/ynasr/)
 * (@ynasr)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139518)
 * Hi Guys,
 * I finally got to the bottom of this. Used SQL to query wp_em_events though. I
   hope this helps folks that may be in a similar situation. FYI – I am a newbie
   so this is MOST CERTAINLY not best practice … but it works 🙂
 *     ```
       global $wpdb;
       $fivesdrafts = $wpdb->get_results(
       	"
       	SELECT wp_em_events.event_slug, wp_em_locations.location_latitude, wp_em_locations.location_longitude, wp_em_events.event_name, wp_em_events.event_start_time, wp_em_events.event_end_time, wp_em_events.event_start_date, wp_em_events.event_rsvp, wp_em_events.event_attributes, wp_terms.name
       	FROM wp_em_events
       	INNER JOIN wp_em_locations
       	ON wp_em_events.location_id=wp_em_locations.location_id
   
       	inner join wp_term_relationships
       	on wp_em_events.post_id = wp_term_relationships.object_id
   
       	inner join wp_term_taxonomy
       	on wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_id
   
       	inner join wp_terms
       	on wp_term_taxonomy.term_id = wp_terms.term_id
   
       	WHERE wp_em_events.event_start_date='$Dt'
       	AND wp_em_events.event_start_time='$fromSQL'
       	AND wp_em_events.event_end_time='$toSQL'
       	AND wp_terms.name = '$category'
   
       	", ARRAY_A
       );
   
       ?>
       ```
   
 * Thanks again for the great plugin guys!
 * Best,
    Yvan

Viewing 6 replies - 16 through 21 (of 21 total)

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

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, 4 months ago](https://wordpress.org/support/topic/wp_query-issue/page/2/#post-7139518)
 * Status: resolved