Home › Forums › Calendar Products › Events Calendar PRO › Event order the wrong way around
- This topic has 19 replies, 5 voices, and was last updated 10 years, 8 months ago by
Support Droid.
-
AuthorPosts
-
August 12, 2015 at 6:29 am #995349
Filip
ParticipantThis is what I use (as per documentation)
<?php $spr = array( 'post_status'=>'publish', 'post_type'=>array(TribeEvents::POSTTYPE), 'posts_per_page'=>3, //order by startdate from newest to oldest 'meta_key'=>'_EventStartDate', 'orderby'=>'_EventStartDate', 'order'=>'DESC', //required in 3.x 'eventDisplay'=>'custom', //query events by category 'tax_query' => array( array( 'taxonomy' => 'tribe_events_cat', 'field' => 'slug', 'terms' => 'grotekerkplein', 'operator' => 'NOT IN' ), ) ); $get_posts = null; $get_posts = new WP_Query(); $get_posts->query($spr); if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?> <? $spr_id = get_post_thumbnail_id(); $spr_url = wp_get_attachment_image_src($spr_id,'large'); $spr_url = $spr_url[0];?> <article style="background: url(<? echo $spr_url ?>) center no-repeat; background-size: cover"> <div class="meta"> <!--what--> <? echo str_replace( ':', '', tribe_get_event_categories($post->ID, array('label'=>'')) ); ?> <!--when--> <span class="when"> <?php echo tribe_get_start_date($post->ID, false, 'j F Y'); ?> - <?php if (tribe_event_is_all_day($event_id)) { echo 'Gehele dag'; } else { echo tribe_get_start_date($post->ID, false, 'H:i').'-'.tribe_get_end_date($post->ID, false, 'H:i'); } ?> </span> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h1> </div> </article> <?php endwhile; endif; wp_reset_query(); ?>As can be seen on the homepage of the live site however the order of the events is the other way around. Please advise, thanks.
August 12, 2015 at 11:29 am #995507Brian
MemberHi,
Thanks for using our plugins.
I looked at the coding and does it help to change this:
'order'=>'DESC',to this:
'order'=>'ASC',Let me know if that changes the order.
Thanks
August 13, 2015 at 12:50 am #995655Filip
ParticipantI tried that on the rightmost eventlist, and indeed it changed the order but now shows events that already have passed. I did not change the calendar on the left. Please advise, thanks.
FWIW; your solution is contrary to documentation, correct?
August 13, 2015 at 7:51 am #995762Brian
MemberHi,
Which example are you referring to for documentation?
On this page we do not have orber in our examples:
And using
'eventDisplay' => 'list'Will only return future events instead of custom so that might be better to use.
I would recommend using tribe_get_events over the WP_Query.
August 14, 2015 at 1:00 am #995980Filip
ParticipantWell, I tried this (on local installation) and what do you know, an old bug resurfaced `
Warning: strtotime() expects parameter 1 to be string, object given in /media/sites/www.clientname.dev/wp-content/plugins/the-events-calendar/src/Tribe/Query.php on line 223
`
As stated 8 months ago Apparently documentation was not updated. Will apply own fix, then report back.August 14, 2015 at 1:06 am #995984Filip
ParticipantOk, I have the code below, but nothing shows.
<? // Retrieve the next 5 upcoming events $events = tribe_get_events( array( 'posts_per_page' => 4, 'taxonomy' => 'tribe_events_cat', 'field' => 'slug', 'terms' => 'grotekerkplein', 'operator' => 'IN', 'start_date' => strtotime('now') ) ); // Loop through the events, displaying the title // and content for each foreach ( $events as $event ) { ?> <article style="background: url(<? echo $spr_url ?>) center no-repeat; background-size: cover"> <div class="meta"> <!--what--> <? echo str_replace( ':', '', tribe_get_event_categories($post->ID, array('label'=>'')) ); ?> <!--when--> <?php if (tribe_get_start_date() !== tribe_get_end_date() ) { ?> <span class="when"> <?php echo tribe_get_start_date($post->ID, false, 'j F Y H:i'); ?> - <?php echo tribe_get_end_date($post->ID, false, 'H:i'); ?> <?php } else { ?> <?php echo tribe_get_start_date($post->ID, false, 'j F Y H:i'); ?> <?php } ?></span> <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?> </a></h1> </div> </article> <?} ?>When I leave out `’taxonomy’ => ‘tribe_events_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘grotekerkplein’,
‘operator’ => ‘IN’,`
it still shows nothing. Please advise, thanks.-
This reply was modified 10 years, 8 months ago by
Filip.
August 14, 2015 at 1:14 am #995986Filip
ParticipantI discovered that if I do strtotime(‘now’) I get no results, and when I do ‘new DateTime()’ I get the PHP error ‘strtotime() expects parameter 1 to be string’. Please advise, thanks.
August 14, 2015 at 1:18 am #995987Filip
ParticipantAnd back to square one
<div id="grotekerk"> <? // Ensure the global $post variable is in scope global $post; // Retrieve the next 5 upcoming events $events = tribe_get_events( array( 'posts_per_page' => 4, 'category_name' => 'grotekerkplein', 'start_date' => new DateTime() ) ); // Loop through the events: set up each one as // the current post then use template tags to // display the title and content foreach ( $events as $post ) { setup_postdata( $post ); // This time, let's throw in an event-specific // template tag to show the date after the title! echo '<article><div class="meta">'; echo str_replace( ':', '', tribe_get_event_categories($post->ID, array('label'=>'')) ); echo tribe_get_start_date($post->ID, false, 'j F Y H:i'); echo '<h1>'.get_the_title().'</h1>'; echo '</div></article>'; } ?>Gives 4 copies of the same event.
August 14, 2015 at 8:02 am #996050Brian
MemberHi,
I changed some things around and got this to work:
<div id="grotekerk">
<?// Retrieve the next 5 upcoming events
$events = tribe_get_events( array(
'posts_per_page' => 4,
'tribe_events_cat' => 'grotekerkplein',
'start_date' => new DateTime()
) );// Loop through the events: set up each one as
// the current post then use template tags to
// display the title and content
foreach ( $events as $event ) {
setup_postdata( $event );// This time, let's throw in an event-specific
// template tag to show the date after the title!
echo '<article><div class="meta">';
echo str_replace(
':',
'',
tribe_get_event_categories($event->ID, array('label'=>''))
);
echo tribe_get_start_date($event->ID, false, 'j F Y H:i');
echo '<h1>'.get_the_title( $event->ID ).'</h1>';
echo '</div></article>';
}
?>
</div>
<?phpAugust 18, 2015 at 12:17 am #996844Filip
ParticipantWell that works, but still leaves me with this error message
Warning: strtotime() expects parameter 1 to be string, object given in /media/sites/www.clientname.dev/wp-content/plugins/the-events-calendar/src/Tribe/Query.php on line 223August 18, 2015 at 12:33 am #996846Filip
ParticipantAnd I’d like to know how I can exclude a category for the first loop on the page.
$events = tribe_get_events( array( 'posts_per_page' => 4, 'tax_query' => array( 'taxonomy' => 'tribe_events_cat', 'field' => 'slug', 'terms' => 'grotekerkplein', 'operator' => 'NOT IN' ), //'tribe_events_cat' => 'grotekerkplein', 'start_date' => new DateTime() ) );I tested this but it does not work,
August 19, 2015 at 8:31 am #997234Geoff
MemberHey there, Filip! Just wanted to follow-up with you here since Brian is out on vacation this week and make sure this thread keeps moving.
When you say “first” loop, do you mean that you have more than one query for events on the page? That’s fine, but you can also add those category exclusion parameters from the snippet you referenced above directly into the query you’ve been working on here with Brian.
Here’s an example of how to exclude specific categories from an event query using a filter. Note that the example does this specifically for Month and List views, but those conditions can be taken out, if needed.
Cheers!
GeoffAugust 20, 2015 at 2:35 am #997502Filip
ParticipantWhen you say “first” loop, do you mean that you have more than one query for events on the page? That’s fine, but you can also add those category exclusion parameters from the snippet you referenced above directly into the query you’ve been working on here with Brian.
I tested this but it does not work,
It is my assumption that tribe_get_events is another form of get_posts and as per codex I cannot filter out a taxonomy in get_posts.
My initial code used wp_query, but I was told that I’d be better off using tribe_get_events. And now I get even more code. Althought I appreciate the support (i am a paying customer) it bothers me that the documentation is so fragmented and ambivalent.
Please guide me to a final solution quickly as the issue is viewable on a live site.
When you say “first” loop, do you mean that you have more than one query for events on the page?
As is viewable on the live site, of which I had to input the url when making this support request in the first place.
August 20, 2015 at 3:18 am #997506Filip
ParticipantNevermind; please refer to my previous post.
-
This reply was modified 10 years, 8 months ago by
Filip. Reason: Caching issue prevented proper display for this substep (not the original issue)
August 21, 2015 at 1:59 pm #998030George
ParticipantHey @Filip,
There are two things I would like to apologize for.
First is the fact that having this thread handled by several different team members may give the impression of a splintered team or a lack of central concern about your issues. I hope you don’t think this is the case, because it’s not! 🙂 Brian headed out for a well-deserved vacation this week, so in his absence the team is collectively managing his persisting threads.
Secondly is the fact that you found our documentation frustrating and ambivalent. It is hard to do documentation right – your feedback will help us keep working towards doing that and is much appreciated.
Now, onto your issues themselves.
There are few things I think are worth pointing out if we can step back from this for a second. We should keep in mind that, at core, this is a customization question. You are asking how to do something with custom code on your site. We officially do not offer any support for this, with some documentation to give people suggestions to get them started, but a strict limit about how much we can help with custom code.
So at the end of things, handling custom code on your site and writing custom features is something you’ll have to take the reins on.
Of course, we’re not complete robots and you are absolutely right about being a paying customer – something we appreciate immensely. So we indeed are trying to help here and I hope we can help a bit more to bring things to fruition on your site.
With that in mind, then, I’d like to point out that Brian’s code solution above should work quite well for you. The warning about the strtotime() function is unfortunately the result of your site running on an old/outdated PHP version, and there’s no way to get around that other than the addition of ‘now’ like Brook originally highlighted on the wordpress.org forum thread you linked to from several months ago.
You yourself said, “That works, but leaves me with this message”, then highlighted the strtotime() error (in response to Brian’s code solution above, which is what I’m talking about – the one from August 14 ).
So if you change new DateTime() to strtotime( ‘now’ ), that may help with that error. If not, then regardless of us or our documentation or anything at all, you will continue to get that error until you upgrade that site’s version of PHP.
So this seems, to me, to leave the only outstanding issue then be the failure of the tax_query filter to work correctly.
The problem with that seems to be that you’re going one dimension too short in your tax_query array. So, instead of this like you currently have:
'tax_query' => array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'grotekerkplein',
'operator' => 'NOT IN'
),
Try specifying those query parameters like this:
'tax_query' => array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => array( 'grotekerkplein' ),
'operator' => 'NOT IN'
)
),
-
This reply was modified 10 years, 8 months ago by
-
AuthorPosts
- The topic ‘Event order the wrong way around’ is closed to new replies.
