Home › Forums › Calendar Products › Events Calendar PRO › tribe_is_month() boolean returning true
- This topic has 14 replies, 2 voices, and was last updated 12 years, 9 months ago by
Barry.
-
AuthorPosts
-
July 9, 2013 at 9:32 am #54026
Cinch
ParticipantUsing Widget Logic, tribe_is_month returns true always.
It also returns true when testing as such:
<?php if (tribe_is_month() ) { ?>
<p>Yo, it's working, or maybe it's not! </p>
<?php } ?>
The goal is to have a widget only show on the main calendar page (month view) and any other time a month view is shown. Currently it’s showing on every page.
There may be other conditionals that could work as well, if anyone has ideas.
Thanks,
~ BryanJuly 9, 2013 at 10:07 am #54034Barry
MemberHi Bryan,
I don’t have a copy of widget logic to hand but that isn’t what I find when I do my own testing. Besides your use of the conditional in widget logic, where else are you applying this (such as in your example)?
Using it too early, or too late, could possibly return an erroneous result.
July 9, 2013 at 10:16 am #54040Cinch
ParticipantHi Barry,
Widget Logic is the only place I need to use this conditional. The example above was just a test run in a widget to see if it fires, which it did, even when not on a month view page. Perhaps that conditional is only available within the context of the plugin?
How would you go about displaying a widget only on the main calendar page?
Thanks for the quick reply,
~ BryanJuly 9, 2013 at 11:19 am #54063Barry
MemberGreat question.
If tribe_is_month() is called too early in the request (specifically, before the parse_query hook runs) then it will result in a boolean false result regardless of what is actually about to be displayed. Looking at Widget Logic, it makes it’s assessment earlier in the request, hence the problem.
So alternative approaches here could be to create a different sidebar to be used only on event pages or else you might do something basically similar to Widget Logic, but adapted to work its magic later in the lifetime of the request.
July 9, 2013 at 11:28 am #54065Cinch
ParticipantI think your approach at conditionally showing the sidebar is the way I’ll go.
The odd thing is that tribe_is_month() is returning true in this situation. The site is still in heavy development so I can’t say for 100% certainty that nothing else has changed, but this setup worked in the prior version.
Anyway, I’m off to conditionally show the sidebar. Thanks for the idea.
~ Bryan
July 9, 2013 at 11:53 am #54073Cinch
ParticipantHi Barry,
Odd, but this is returning true on every page as well:
July 9, 2013 at 11:55 am #54074Cinch
ParticipantSorry… that code snip didn’t work… here it is again:
if ( tribe_is_month() ) {
get_sidebar( 'after-content' );
}
July 9, 2013 at 12:06 pm #54079Barry
MemberUnfortunately the forum isn’t very tolerant of code, so it’s usually best to use a service like Pastebin, Gist or similar and share a link to it.
That snippet in your last post looks like it should do the job … can you confirm where you are using it?
July 9, 2013 at 12:16 pm #54082Cinch
ParticipantI’m using it within footer.php
I’m having a similar conditional issue here: https://theeventscalendar.com/support/forums/topic/cpt-conditionals-for-filters/
Perhaps I’ve got something more systemic going on.
Is it possible to downgrade back to v 2.xx? I don’t see it in the downloads.
July 9, 2013 at 12:31 pm #54093Cinch
ParticipantI had a backup and was able to downgrade to v2.0.11 – which has solved all my conditional problems…
I’ll have to stay at the older version until I can locate the issue.
If I figure it out I’ll post back here.
Thanks,
~ BryanJuly 9, 2013 at 1:14 pm #54109Barry
MemberSorry to hear that – a number of things have changed as of 3.0 won’t carry over without modification.
As things progress with 3.0 and the community at large – as well as the support team – build up a further body of knowledge it will doubtless become easier to transition.
As an aside, if you (or anyone else reading this) does need a historical version then please simply email us at pro (at) tri (dot) be with a brief explanation and one of the team will be happy to help.
July 9, 2013 at 1:30 pm #54124Cinch
ParticipantI’d really like to transition now to 3.0 as we’re still in development. Can you think of any reason why normal WP conditionals might simply stop working when using the new version?
This conditional also isn’t firing correctly:
if ( get_post_type($post_id) == 'tribe_events' ) { ... }
July 9, 2013 at 2:07 pm #54135Barry
MemberWhat is the value of $post_id? I know it seems like an almost too obvious point – but does it definitely relate to an event (how are you obtaining it)?
Remember that multiple queries and loops sometimes run to construct a single page, so you would need to catch this while the context is still an event related one, if that makes sense.
July 9, 2013 at 2:08 pm #54136Cinch
ParticipantThat was actually just a bit of a test… the $post_id there didn’t make a difference and I’ve removed it. Still testing…
July 9, 2013 at 2:19 pm #54138Barry
MemberOK – I mean if $post_id is set to an appropriate, valid value then that code ought to work as expected.
-
AuthorPosts
- The topic ‘tribe_is_month() boolean returning true’ is closed to new replies.
