Parameters when passed as an array doesn’t work

Home Forums Calendar Products Events Calendar PRO Parameters when passed as an array doesn’t work

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1273185
    Robert
    Participant

    Thanks for the great plugin
    I am using following query to get events ..
    $events = tribe_get_events( array(
    'eventDisplay' => 'custom',
    'posts_per_page' => 20,
    'tribe_events_cat' => $tribe_events_cat,
    'start_date' => $event_start_date,
    'venue'=>$locations,
    ));

    Everything is working fine but when I try to pass parameters as array they don’t work

    For eg:

    Doesn’t work:
    $tribe_events_cat= array('event1' , 'event2');
    $location = array(1,2,3);

    Works

    $tribe_events_cat= 'event';
    $location = 33;

    So please help

    thanks

    #1273781
    Robert
    Participant

    I get the following warning when I try to pass array of event categories
    Warning: urlencode() expects parameter 1 to be string, array given in

    I even noticed that when i try to get all the event categories for each event using following
    $myterms = wp_get_post_terms( $event->ID, TribeEvents::TAXONOMY);

    or

    tribe_get_event_categories($event->ID, array(
    ‘echo’ => false,
    ‘label’ => ”,
    ‘label_before’ => ”,
    ‘label_after’ => ”,
    ‘wrap_before’ => ”,
    ‘wrap_after’ => ”,
    ))

    I still get only one category per event even when most of events have multiple categories

    Looking forward to your response

    #1273828
    Cliff
    Member

    Hi, Robert.

    The issue here is that tribe_events_cat and venue are not valid arguments.

    tribe_get_events() is just a wrapper for get_posts() and those 2 aren’t valid arguments.

    Please reference https://theeventscalendar.com/knowledgebase/using-tribe_get_events/ and let me know if you have any follow-up questions on this topic.

    ===

    Note: you could request these as a new feature (or maybe search to see if the idea was already posted by someone else) at our plugins’ UserVoice page.

    This allows others who are interested in that feature to easily voice their support. We frequently review suggestions there to find out which ones are popular, then we implement as many of them as we can.

    If you post it / find it, feel free to link to it from here in case anyone comes across this forum thread in the future.

    #1279435
    Robert
    Participant

    Hey

    thanks for replying..
    May be I figured it out and may be its the right way

    I tried this and

    $tax_query[] =  array(
    			    	array(
    			        'taxonomy' => 'tribe_events_cat',
    			        'field' => 'slug',
    			        'terms' => $terms
    	              ) );
    
    $meta_query = array(
    array(
        'key' => '_EventStartDate',
        'value' => $event_start_date,
        'compare' => '>',			                
    
    ));
    
    global $post;
    $events = tribe_get_events( 
    			array(
    				'eventDisplay' => 'custom',
    				'posts_per_page' => 20,
    				'tax_query'=>$tax_query,
    				'venue'=>$venue,
    				'meta_query' => $meta_query
    			));
    
    foreach ($events as $post):
    	setup_postdata( $post );
    	$post->post_title;
    endforach;
     

    Now I am facing other issue that ‘compare’ => ‘=’ is not working ..

    If I select date 2017-05-01 ,then it doesn’t show me anything ..

    But is I try ‘compare’ => ‘>=’ , then i show me all the events on that date and after that

    But what I want is the events on that particular day only ..

    I hope you can give me a quick solution

    • This reply was modified 9 years ago by Robert.
    #1279538
    Cliff
    Member

    Thanks for that detailed question.

    I can’t definitively tell you because I don’t know what your variables are set to, but here are a few thoughts:

    • maybe change $event_start_date to date( $event_start_date )
    • if that doesn’t work, maybe hardcode it to date( ‘2017-05-01’ ) just to see if it’s working as expected
    • make sure $venue is an integer (post ID of a Venue post type)

    It could also help to reference the function itself, including it’s documentation: https://github.com/moderntribe/the-events-calendar/blob/4.5.1/src/functions/template-tags/general.php#L183-L219

    Please let me know how this goes for you.

    #1285329
    Robert
    Participant

    Hey Cliff
    The link you gave me didn’t work

    But I searched a lot and solved this by following code

    $event_start_date = $event_start_date1.’ 00:00′;
    $event_end_date =$event_start_date1.’ 23:59′;
    $meta_query = array(
    ‘relation’=>’AND’,
    ‘start’=> array(
    ‘key’ => ‘_EventStartDate’,
    ‘value’ => $event_start_date,
    ‘compare’ => ‘>=’,
    ),
    ‘end’=>array(
    ‘key’ => ‘_EventStartDate’,
    ‘value’ => $event_end_date,
    ‘compare’ => ‘<=’,
    ),
    );

    if($terms && $tags){
    $tax_query[] = array(
    ‘relation’ => ‘AND’,
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => $terms
    ),
    array(
    ‘taxonomy’ => ‘post_tag’,
    ‘field’ => ‘name’,
    ‘terms’ => $tags
    )
    );

    }elseif($tags){
    $tax_query[] = array(
    array(
    ‘taxonomy’ => ‘post_tag’,
    ‘field’ => ‘name’,
    ‘terms’ => $tags
    )
    );
    }elseif($terms){
    $tax_query[] = array(
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => $terms
    ) );
    }
    else{
    }

    if($locations){
    $venue=$locations;
    }

    global $post;
    $events = tribe_get_events( array(
    ‘eventDisplay’ => ‘custom’,
    ‘posts_per_page’ => 20,
    ‘tax_query’=>$tax_query,
    ‘venue’=>$venue,
    ‘meta_query’ => $meta_query,
    ‘orderby’=>’_EventStartDate’,
    ‘order’=>’DESC’,
    ));

    #1285331
    Robert
    Participant

    This reply is private.

    #1285908
    Cliff
    Member

    tribe_get_events() uses get_posts(), which doesn’t support pagination.

    You should instead be using WP_Query instead if you need pagination. (reference)

    Thankfully, the code you already have should be easily ported to the WP_Query format.

    #1286101
    Robert
    Participant

    wp_query will do the trick for sure
    But I am not sure if the following parameters will work or not?

    ‘eventDisplay’ => ‘custom’,
    ‘venue’=>$venue,

    #1286182
    Cliff
    Member

    tribe_get_events() uses getEvents() which runs WP_Query with the passed $args… so maybe keep those in there and give it a shot?

    References:

    Please let me know how this goes for you.

    #1296175
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Parameters when passed as an array doesn’t work’ is closed to new replies.