• Resolved Ynasr

    (@ynasr)


    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://www.ads-software.com/plugins/events-manager/

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter Ynasr

    (@ynasr)

    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

    (@angelo_nwl)

    here’s another thread which may help you with this – https://www.ads-software.com/support/topic/em-with-wp_query-and-orderby-date?replies=15

    Thread Starter Ynasr

    (@ynasr)

    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

    What WordPress called authors, Events Manager calls Event Owners. 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

    (@ynasr)

    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

    (@ynasr)

    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

    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

    (@ynasr)

    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

    (@angelo_nwl)

    maybe you can try to use global $wpdb if you want to query the events table

    Thread Starter Ynasr

    (@ynasr)

    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

    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

    (@ynasr)

    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

    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

    (@ynasr)

    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

    (@ynasr)

    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)
  • The topic ‘wp_query issue’ is closed to new replies.