Are you pulling events using WordPress posts, rather than by using the My Calendar event lists? The posts aren’t meant to be pulled independently; they’re more of a data store for My Calendar.
Hi Joe,
I am trying to do more of a ‘show if there are Events’. So I have the event calendar shortcode ready to be displayed…but I only want to display that if there are ‘published’ events (not ones set to Draft).
Can you think of a way to do that? Am I overlooking something?
Thanks in advance…
Are you trying to set things up so you only show the calendar if there are any events published, regardless of the date of those events, or do you need there to be events within the current month/within the current view parameters of the calendar?
What I’m not sure about, I guess, is what you consider to be the “no events” scenario.
I am using the shortcode…
[my_calendar_upcoming before=”0″ after=”5″ show_today=”yes” type=”event” order=”asc”]
What I am trying to do is a conditional so that if there are no published events, the shortcode (along with some other information) doesn’t show and instead a different message appears.
I’ve attempted this with if (wp_count_posts('mc-events')->publish > 0 )
But even Draft events will return true.
Ah, upcoming events. Is there a reason you’re not using the fallback parameter for the upcoming events shortcode? That sets a block of text to show if there are no events to display.
Thanks for that…but I’m actually trying to do the opposite. I want to display a message when there are published events.
Any suggestions there?
The simplest solution off hand would be to test the value of the upcoming events shortcode for the presence of your fallback string, e.g.
$output = do_shortcode( '[my_calendar_upcoming]' ); // with your arguments, whatever they are.
// If the fallback string is not present...
if ( false === stripos( $output, 'My Fallback String' ) ) {
echo 'the content I want to show';
}
echo $output; // echo the shortcode.