Home › Forums › Calendar Products › Events Calendar PRO › Parameters when passed as an array doesn’t work
- This topic has 11 replies, 2 voices, and was last updated 8 years, 11 months ago by
Robert.
-
AuthorPosts
-
April 22, 2017 at 11:25 pm #1273185
Robert
ParticipantThanks 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 workFor 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
April 24, 2017 at 4:54 pm #1273781Robert
ParticipantI get the following warning when I try to pass array of event categories
Warning: urlencode() expects parameter 1 to be string, array given inI 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
April 24, 2017 at 7:52 pm #1273828Cliff
MemberHi, 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.
May 5, 2017 at 11:44 am #1279435Robert
ParticipantHey
thanks for replying..
May be I figured it out and may be its the right wayI 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.
May 5, 2017 at 12:45 pm #1279538Cliff
MemberThanks 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.
May 18, 2017 at 12:22 am #1285329Robert
ParticipantHey Cliff
The link you gave me didn’t workBut 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’,
));May 18, 2017 at 12:29 am #1285331Robert
ParticipantThis reply is private.
May 18, 2017 at 3:39 pm #1285908Cliff
MemberMay 19, 2017 at 2:29 am #1286101Robert
Participantwp_query will do the trick for sure
But I am not sure if the following parameters will work or not?‘eventDisplay’ => ‘custom’,
‘venue’=>$venue,May 19, 2017 at 5:15 am #1286182Cliff
Membertribe_get_events() uses getEvents() which runs WP_Query with the passed $args… so maybe keep those in there and give it a shot?
References:
- https://github.com/moderntribe/the-events-calendar/blob/4.5.1/src/functions/template-tags/general.php#L183-L219
- https://github.com/moderntribe/the-events-calendar/blob/4.5.1/src/Tribe/Query.php#L1017
Please let me know how this goes for you.
June 10, 2017 at 9:35 am #1296175Support Droid
KeymasterHey 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 -
This reply was modified 9 years ago by
-
AuthorPosts
- The topic ‘Parameters when passed as an array doesn’t work’ is closed to new replies.
