How-to: Custom Post Types for Events Pt. 2

Now that we’ve handled the entire registration and back-end functionality (see Pt. 1) of our events custom post type, it’s time to move on to our design output (download the file for this tutorial here)! There’s no point in having fancy custom post types if you can’t display them properly. As you may remember, the entire reason for me requiring this functionality is for my Pub Theme (Pubforce), so I need to give my clients some flexibility with regards to its use. As you can see from the screenshot below, I have the following designs: 1) Featured (Shown with Big Thumbnail), 2) Full Listing (which groups by day) and 3) Widget Listing (again, grouping by day).

I don’t want to hinder my end-users in any way so I’ve chosen to use shortcodes to let them decide where and how they want to deploy events within the main area, so let’s get right to that! My tutorial below will revolve around design #2 above.

1) shortcode structure

Shortcodes remind me a lot of Excel macro’s; very detailed scripts serving a specific purpose, yet simple enough that they allow non-developers the ability to pass parameters and make use of them where and how they want. This is a massive plus over something like a page template which is a lot more rigid in its ways.

Incase you’re not all too familiar with shortcodes, I’ve laid out the basic structure below (but be sure to read the relevant codex article):

function shortcode_function ( $atts ) {

	// - define arguments -
	extract(shortcode_atts(array(
		'name' => '',
	 ), $atts));

	// - spit output -
	$output = 'My name is' . $name;
	return $output;
	}

add_shortcode('introduction', 'shortcode_function');

?>

Thus, if I were to now insert [introduction name="Noel"] in a post, I’d get “My name is Noel“. Really hard right? As the code is going to get really long after, I’m just going to take it one step further to show you the shell of the shortcode we’ll create today. We’re going to use a nifty little function called Output Buffer (which just collects everything that is produced, starting with ob_start() and ending with ob_get_contents()). This will save us from having to piece everything together a different way (shortcodes require the use of ‘return‘, hence all this messing around):

function tf_events_full ( $atts ) {

	// - define arguments -
	extract(shortcode_atts(array(
		'limit' => '10', // Default amount of events to show
	 ), $atts))

	// - start grabbing output -
	ob_start();

	// - generate output -

	... next step of the tutorial ...

	// - spit output -
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
	}

add_shortcode('tf-events-full', ' tf_events_full');

?>

Now that we have the shell of our shortcode, lets move on to more interesting things shall we.

2) query

Although tradition would have dictated I use a built-in function such as wp_query, I wanted to leave my options down the road without having to rewrite everything. This is why I’m using a custom select query which lets you do anything you want (more or less).

// - hide events that are older than 6am today -

$today6am = strtotime('today 6:00') + ( get_option( 'gmt_offset' ) * 3600 );

// - query -
global $wpdb;
$querystr = "
    SELECT *
    FROM $wpdb->posts wposts, $wpdb->postmeta metastart, $wpdb->postmeta metaend
    WHERE (wposts.ID = metastart.post_id AND wposts.ID = metaend.post_id)
    AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $today6am )
    AND metastart.meta_key = 'tf_events_enddate'
    AND wposts.post_type = 'tf_events'
    AND wposts.post_status = 'publish'
    ORDER BY metastart.meta_value ASC LIMIT $limit
 ";

$events = $wpdb->get_results($querystr, OBJECT);

You’ll notice right at the top that I’m defining this variable called $today6am. Given my clients all run Pubs, I figured this would be a good time to make events disappear. I like the concept of removing dates on a daily basis as opposed to when they occur, and seeing as many events go into the early morning, I found 6am to be a happy medium to remove events that happened on the day before. You’ll also see that I’m conscious of the local timezone by multiplying the timezone difference in hours (gmt_offset) by how many seconds there are in an hour (3600). Adding this value to the Unix timestamp means it’s always 6am local time. Also note that I’m comparing against the event end time (as some events are full-day).

It’s also important that we call the postmeta twice (metastart & metaend), this way we can use the start & end time for their respective purposes; start for sorting the events and end for checking if they have expired.

Also, you’ll remember that $limit is a parameter passed through the shortcode (default ’10’).

3) loop

Now the loop itself, as mentioned above this is the final look we’re trying to achieve:

In order to do that, this is the code we’ll require (starting off with the loop declaration itself and any variables we’d like to use in our final output):

// - declare fresh day -
$daycheck = null;

// - loop start -
if ($events):
global $post;
foreach ($events as $post):
setup_postdata($post);

// - custom variables -
$custom = get_post_custom(get_the_ID());
$sd = $custom["tf_events_startdate"][0];
$ed = $custom["tf_events_enddate"][0];

// - determine if it's a new day -
$longdate = date("l, F j, Y", $sd);
if ($daycheck == null) { echo '<h2 class="full-events">' . $longdate . '</h2>'; }
if ($daycheck != $longdate && $daycheck != null) { echo '<h2 class="full-events">' . $longdate . '</h2>'; }

// - local time format -
$time_format = get_option('time_format');
$stime = date($time_format, $sd);
$etime = date($time_format, $ed);

?>

… followed by the XHTML output …

<div class="full-events">
    <div class="text">
        <div class="title">
            <div class="time"><?php echo $stime . ' - ' . $etime; ?></div>
            <div class="eventtext"><?php the_title(); ?></div>
        </div>
    </div>
     <div class="desc"><?php if (strlen($post->post_content) > 150) { echo substr($post->post_content, 0, 150) . '...'; } else { echo $post->post_content; } ?></div>
</div>

… and finally the end of the loop …

<?php

// - fill daycheck with the current day -
$daycheck = $longdate;

// - go back to the top -
endforeach;
else :
endif;

You’re probably wondering what all those ‘day’ variables are? Well they’re there to help us group the events into days like the design above! Let me break it down so it makes more sense (see commenting):

// - declare fresh day -
$daycheck = null;

... loop starts ...

// - convert date -
$longdate = date("l, F j, Y", $sd);

// - if it's our first event, echo date as title -
if ($daycheck == null) { echo '<h2 class="full-events">' . $longdate . '</h2>'; }

// - if the date has changed since the last post, echo date as title -
if ($daycheck != $longdate && $daycheck != null) { echo '<h2 class="full-events">' . $longdate . '</h2>'; }

... output rest of event ...

// - fill daycheck with the current day -
$daycheck = $longdate;

... loop ends and repeats ...

4) bonus: featured loop

Now that we’ve got the regular event listing done, I figured I’d go an extra step to show you how a featured event is displayed. The big difference here is that we’ll be using the custom taxonomy that we created to help filter results. Specifically, the end user will be able to select ‘Featured’ to trigger the required visibility:

Instead of repeating the entire code, I’m just going to show you the actual query, which is the most important change (as it now involves pulling in taxonomy data):

global $wpdb;

$querystr = "
SELECT *
FROM $wpdb->postmeta metastart, $wpdb->postmeta metaend, $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
WHERE ($wpdb->posts.ID = metastart.post_id AND $wpdb->posts.ID = metaend.post_id)
AND $wpdb->term_taxonomy.taxonomy = 'tf_eventcategory'
AND $wpdb->terms.name = '$group'
AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $today6am )
AND metastart.meta_key = 'tf_events_enddate'
AND $wpdb->posts.post_type = 'tf_events'
AND $wpdb->posts.post_status = 'publish'
ORDER BY metastart.meta_value ASC LIMIT $limit
";

$events = $wpdb->get_results($querystr, OBJECT);

You’ll notice I’ve also got a new variable in the mix called $group, this is by default ‘Featured’, however can be overridden by the user through the shortcode (maybe they only want to show Soccer matches). This is the sort of flexibility you want to give to your clients.

It would have also been possible to just create a checkbox within the custom post type, but again we’d be limiting user options and not making use of well-functioning WP code.

5) your turn to speak!

Your options are endless with this setup (you can downloaded the entire file here), but you’ll always need to beware of the amount of queries it runs as it can really be taxing on the server (check out my post on my development environment for more information on debugging).

If you have any suggestions, comments or ways you’d do things differently, please let me know by commenting below! I’d love to hear your take on this as well as your experiences. Feel free to ping me on Twitter @noeltock or retweet this message, always appreciated!

  • http://dstltz.com Zech

    Thanks man for the post, been visiting the your site everyday waiting for this part. Wow its awesome, be blessed

  • Zeeshan

    Is there a demo somewhere ??

  • Noel

    Hi Zeeshan,

    There will be once I’m done with my updates of Pubforce (but I think the images make it quite self-explanatory for now).

    Cheers, Noel

  • http://dstltz.com Zech

    Just one question, where do we add all these codes ( i’m talking about the part 2 of the tutorial)

  • George Mamadashvili

    Hello Noel.

    Can you add archive with final results? Yes I know we can download php file in fist part, but if you can add js and css files used in tutorial that would be awesome.

    Thanks, George

  • Noel

    Hi George,

    Yep, I’ll add a zip file for this, I’ll throw in the datepicker too. There’s no real CSS for this part and I think I included it for the previous one (within the text).

    Will be up in the next hour or so!

    Cheers
    Noel

  • http://richardsweeney.com Richard Sweeney

    Thanks for a really fantastic tutorial!

    I do a lot of work for musicians, and have been on the hunt for something like this! Would make a perfect concert diary!

    Is this something you’d consider making into a plugin?

    I don’t wish to seem ungrateful, but might you consider also adding the CSS and JS files to the download? It’s a bit of a shame to have to guess which features of the jQuery UI you use..! Even pointing towards the google ajax api would be really sweet!

    I’d really appreciate if you had the time and thanks again for the tutorial!

    Richard

  • Noel

    Hi Richard,

    Thanks for the kind comments! Seems like I had uploaded the wrong file, check now. It’s all there except for the front-end CSS (which everybody does differently, and mine is nothing more then a few floats). However, all the other stuff is in there now (JS, Admin CSS, Image). I’m sort of against the use of plug-ins when you know what exactly what you want/need (otherwise there’s a bunch of Custom Post Type Plug-ins that literally have every feature you could think of).

    Hope your concert diary works out :9

    Cheers

    Noel

  • http://richardsweeney.com Richard Sweeney

    Fantastic!

    Good point re plug-ins and I do really need to improve my sorry PHP skills.

    Thanks so much this, lovely site by the way!

    Richard

  • Paul

    Thanks very much for this tutorial. This is going to be my main reference for future projects!

  • http://everydaytype.com Nick Cox

    Wow. This is great. So helpful. Like Richard said, this would be perfect for bands to post shows. I’m definitely saving this for future projects. Thanks!

  • Don

    Really great tutorial. One of the best uses of Custom Post Types I’ve seen yet. Keep up the great work.

    Here’s to hoping you include the bit for that snazzy sidebar widget (#3) too.

  • Pingback: wpmag.com - WordPress News, Themes, Tutorials, Plugins, Questions, ...

  • tejas

    Hi Noel,

    This is very nicely done!!

    I needed help with one thing. I am using this to display events where time does not matter. In fact, I am not even taking time as an input. In that case, how do I display only the start and end dates?

  • Noel

    Hi Don, thank you and will do!

    Tejas, you still use all of the same fields, just leave out the display of time (i.e. hours & minutes will just default to midnight, 00:00). If you don’t need an end-time, look at Devin’s post (linked to from my first tutorial).

  • Sue

    Thanks so much for this Noel – it is fantastic!
    Just wondering is there any issue using this code with WordPress 3.1?
    I’ve added it in, it works properly, but I get a blank page when I save anything in the admin console since adding it.

    Thanks!

  • Noel

    Hi Sue,

    This should work right off the bat (also 3.1, as it’s all WP code). It’s impossible to tell what the issue exactly is, but I’d check the admin function (last item within 1st pt tutorial) to see if everything was implemented correctly (probably something with the jQuery UI).

    Cheers

    Noel

  • Sue

    I also just noticed the dates / times don’t show in the event column and the code for displaying the events only displays one event if if the limit is set higher in the shortcode.

    Just wondering if you knew if this was a WordPress 3.1 issue too..
    Thanks :)

  • J Heartbeat

    Thanks for a sweet tutorial!

    Getting the full event list working was a breeze but I’ve run into some trouble when I wanted to show all events only from a certain category. I tried using your Featured loop, and managed to get just a certain category showing. But every event shows up multiple times, I suppose the Featured loop is meant to show just a single post.

    So, how would I go about showing all events from a certain category? Your help would be very appreciated!

  • Steve N

    Hello Noel;

    Sorry for the newbie question.
    Following your instruction, I put this in the template’s “sidebar.php” file:
    [mucc-events-full limit='3']
    (I changed your “tf” namespace).
    But it doesn’t get parsed. When viewing the page I see, literally,
    [mucc-events-full limit='3']

    What am I needing to do to get the shortcode parsed?
    Thanks for your patience and help.
    Steve

  • squarecandy
  • Steve N

    Thanks @squarecandy. I was going to update my question to say I had learned about do_shortcode. I also read some warning about dashes in shortcode name, so I changed that. Now I don’t see the literal [muccevents]. Unfortunately, I don’t see anything at all. Studying the database, it appears the custom posts have been stored, and have the proper post type (mucc_events). The entries just don’t show. It’s not a presentation thing – it doesn’t show in the source (html) either.
    Hmmmmmm

  • Noel

    Hi Gents,

    Steve – Thanks for your e-mail, I’m going to have a look at using fullcalendar, doesn’t look all too crazy. Regarding your shortcode, does it work in a post/page, but just not as do_shortcode?

    Cheers

    Noel

  • Steve N

    Noel; I don’t want to turn your blog into a debug forum, and day job is getting in the way of spending more time at this. If I echo something before the ob_start() line, it shows up. Nothing after that. Peering into the database, my post meta keys seem to match what you build the query around, so I’m at a loss to figure out why the shortcode’s loop seems to return nothing. Oh well. Probably missing something that should be obvious. Thanks for your time and interest. Steve

  • Steve N

    When I commented out the ob_start() bits (including the last three lines defining and populating $output) it works. Now to scratch my head and figure out what’s up with the output buffer bit. BUT— REALLY excited that I have this much going, and really grateful to you for sharing Noel! Steve

  • Jonny Pryor

    Hi there,

    Firstly thanks for an amazing tutorial!!
    much love to you x

    Secondly a helping hand if possible,
    I’m trying to implement the featured option,

    It’s displaying the correct posts (only 2 at the moment)
    but its showing 4 of one and 5 of the other!

    Any ideas on why it would show multiple copies of posts would be appreciated.

    Thanks again,

    Jonny

  • Noel

    Hi Jonny,

    Sorry about that, I had updated it in my base files but reflect it here. I removed the first JOIN out of the query (was a duplicate), check out the code now! :)

    Cheers

    Noel

  • Jonny Pryor

    Thank you so much,

    You are a true legend!

  • Sue

    Hello,

    Would you mind telling me if I’m doing something completely wrong?! Thanks :)

    I did a fresh install of WordPress 3.1. I am using the twenty ten theme.

    I downloaded the latest ZIP file from this site. I copied the contens of cpt-events.php and pasted it at the end of functions.php

    I copied the css, images and js files into the twenty ten folder.

    I updated the path to the datepicker image in the js file.

    I now get an 500 internal server error. Have I missed a step?

    Thanks

  • Matt Bivins

    Hey, all,

    I too, have found this set of articles and know for sure that it’s exactly what I need (building an Event system for a jazz organization). I’ve gotten pretty far, too, with my pitiful-but-ever-growing PHP knowledge…but I just can’t figure out how to call the posts and fields into my templates. I’d love the ease of using shortcode, but this lesson kind of lost me completely, so I’m OK with finding a way to just include it in template files.

    I have a few categories, and just can’t figure what’s the first step to query-ing the various categorized Events. And then, of course, I want to be able to send those Events in a list to a single-events.php page, right? …but I’m missing a few steps, because it isn’t working out yet.

    Can someone just point me in a direction suitable for newbies? Some great tutorial to help me bridge the gaps in my knowledge?

    Thanks in advance, and thank you SO MUCH for this tutorial, Noel…I was proud to keep your “tf” in my code, now being “down with the Force”!

    Matt

  • Noel

    Hi Matt,

    Thanks for the kind comments, well appreciated!

    There’s actually a pretty good tutorial out there showing how to insert in a single-x.php . Go to this page:

    http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/

    … and there’s a section called “Making the Theme Template”, that should help you out :)

    Cheers

    Noel

  • Matt Bivins

    Noel,

    Super-helpful, and many thanks for the speedy response!

    I hate to be greedy, but since you were so gracious about that info, could you (or anyone else) point me to the best way to list:

    the top 5 upcoming Events categorized by the custom taxonomy “Orchestra”.

    I want to do this for two categories, at the bottom of my page-home.php template. I can do it with regular old Post Categories but my Google-fu is failing me in my quest to make it happen with these Custom Post Types.

    Again, I’ve got:
    1. a Custom Post Type called “Events”
    2. four Custom Post Taxonomies (“Orchestra”, “JAC”, “Jazz Around Town”, and “Other”)
    3. a desire to show all the upcoming Events categorized as “Orchestra” in a template file.

    Whew! Thanks again!

    Matt

  • Matt Bivins

    OK…I’m getting through this. Here’s the code I am using to do what I wanted above (for those that have the same issues):

    ID, ‘tf_eventcategory’);
    $slugs = array();
    foreach ( $terms as $term )
    $slugs[] = $term->slug;
    $other_posts = new WP_Query(‘post_type=tf_events&tf_eventcategory=cjo-event’.$slugs[0].’&showposts=20&orderby=menu_order’);
    if ($other_posts->have_posts()):
    echo ”;
    while ($other_posts->have_posts()): $other_posts->the_post();
    echo ‘‘.get_the_title().’‘;
    endwhile;
    echo ”;
    endif;?>

    The things to note here are

    1. you’re getting the terms from the Custom Post Types (which Noel named “tf_eventcategory”) at the top, when defining “$terms”
    2. you’re starting the query by defining the Post Type (“tf_events”) and then the specific term of your taxonomy (“tf_eventcategory”). In my case, the particular slug name of the category I wanted to pull was called “cjo-event”, hence the “&tf_eventcategory=cjo-event”
    3. THEN you can style the posts any way you want, using HTML. I only wanted to show titles as permalinks on my home page, but I’m assuming that you can add whatever you’d like from your Categorized Event.

    The only part I’m working out now is how to order the lists by Noel’s custom meta date fields…but maybe it shouldn’t be so hard, since he’s got it working using a shortcode in the article above?

    I’m sorry for this information being so obvious, but again: working it out online might help someone in the exact same learning curve…

    Matt

  • Matt Bivins

    OK, Noel,

    I’m sorry to be over-posting, here. It’s just that I’m…THAT CLOSE to figuring this all out.

    I’m back to working with your shortcodes, and while I can rudimentarily follow your code to add taxonomy functionality, it doesn’t work for me. Now that I’ve gotten my list of Events by Category on the front page, I know that I can get the same list on individual pages, but copying and pasting your query from those functions pages isn’t doing the trick. So I thought that it might be nice to have a shortcode that would do look something like:

    [tf_events_full limit="10" group="cjo-events"]

    that would display my Events grouped by the category “CJO Events” in a list. I think that is what you’re showing is possible with the “Featured” functions at the end of this page.

    I don’t even really need the shortcode, at this point- I just want those categorized Events show up and ordered by the “startdate”!

    I really appreciate your time.

    Matt

  • Noel

    Hi Matt!

    Apologies for the late reply, cross-referencing CPT & Taxonomy data is always a little funny, but has been made easier with WP 3.1. I’ll try to have a look at it tomorrow as it’s possible that the entire query will be edited (and will then look a lot more like: and, if, not, etc.. as opposed to this SQL stuff).

    Cheers

    Noel

  • http://rynoweb.com Chuck Reynolds

    This would be killer as a PLUGIN

    Carry on… :)

  • http://openplans.org/ Andy

    I do not understand why this in the query:
    metastart.meta_key = ‘tf_events_enddate’

    is not this:
    metastart.meta_key = ‘tf_events_startdate’

  • Noel

    Thanks Chuck!

    Hi Andy, the meta_key in this case is used to determine the “cut-off point”, I explain the rationale of this $today6am concept above, but basically, if you have a 5 day event, you wouldn’t want it to drop off the events list on day 1, hence end date.

    Cheers
    Noel

  • http://www.patrickheiloo.nl Patrick Heiloo

    Hi Noel!

    Thanks for this amazing tutorial. I was searching for something like this for a couple of months.

    I have a question about the datepicker. When i’m changing the month names in the pubforce-admin.js file, I get an PHP error in WordPress. I would like to change them to my own language (Dutch). To do this I use the info page from jQuery (http://jqueryui.com/demos/datepicker/).

    This is the error:
    Warning: date() expects parameter 2 to be long, string given in … line 397.

    Maybe you have a solution.

    Patrick

  • Brian

    Hello Noel,

    I dont suppose you have a tutorial on creating a custom post type restaurant menu/wine list. I have been searching for tutorial on this for ages and not found a great deal?
    Many thanks
    Brian

  • Brian

    Hello Noel,

    What is the short code, if there is one, for the smaller/widget sized events display?
    Plus I cannot get the features event to display. Is there a special shortcode parameter for this too?

    Many thanks
    Brian

  • henning

    nice tutorial! for me as a wordpress newbie it was a little hard to follow sometimes but i got it running fine. can someone tell me wich shortcode is need to display my events like in the example? i pasted [ tf-events-full limit='5' ] and it runs fine but i want to: 1.: show only events from 2 categories 2.: highlight the newest event on top with a article-picture 3.: show only the excerpt and with a click on the headline the full article … ?

  • http://www.stagesong.com/ Vezu

    Noel, you are a star, i got this working on my website and i am very great full for your post. I twicked it a little to do what i wanted it to do. http://www.stagesong.com/

    Thanks a million

  • Brian

    Hello Noel,

    I can get the main events list to display but Im having trouble displaying the Featured and Small events list. I cannot see the code for these features in the Source files you have provided.
    It would be great if I could wok out how you created these cool features.

    Many thanks
    Brian

  • miguel

    Hi Noel,

    first of all thanks for this great tutorial, it helped me a lot to understand wordpress better.

    I successfully extended the backend to my needs but I’m facing horrors:-) in the frontend and i’m getting desperate.

    I want to implement this script into my template without using shortcodes so I created a custom category taxonomy template to list the events and added in what i think was right but the HTML outside the PHP does not work.

    Can you help me please? :)

    Cheers,
    miguel

  • frances

    Hi Noel,

    Thanks for this brilliant setup. I was in the middle of working through this on my own and had got to wondering how to best implement start/end dates and times when I found this and promptly dumped what I was doing as your method works so much better.

    I’ve been putting it together for a site that intends to have a lot of different events of different sizes in various cities, and have made some trivial changes (mostly adding extra meta-boxes for maps, featured images, rewriting the date output for single/multi-day events, and so on).

    One thing that I would like to get working but so far isn’t is the featured event loop. I presumed originally this was simply replacing the existing wpdb loop, but when I tried that the entire setup stopped working. I tried various things, even following on from @Matt Bivins above, but nothing worked.

    What am I doing wrong? How have you set this up? Is the wpdb loop separate from the original one?

    I would love to get this part of it working if you have a moment to explain or share the code with this part in it.

    Thanks,

    Frances

  • http://stein.halb6.com Flo

    Hi Noel,

    sorry for bringing up something that has been asked by Andy long ago. I’m pretty sure that he was right by saying:

    =====
    I do not understand why this in the query:
    metastart.meta_key = ‘tf_events_enddate’

    is not this:
    metastart.meta_key = ‘tf_events_startdate’
    =====

    You are assigning the END date to metaSTART.meta_key which leads to a wrong order of the events (because you then write “ORDER BY metastart.meta_value ASC”, therefore all events are now sorted by their end date).

    I testet it – Andy’s line “metastart.meta_key = ‘tf_events_startdate’” does the job correctly.

    The assignment of the start date in this case has nothing to do with several-day events and the $today6am concept. The check has already been done with “metaend.meta_value > $today6am”.

    I hope I’m expressing myself not too complicated :)

    Apart from that – thank you so much! Your posts really are a reference!

    Flo

  • Jonathan

    Hi!

    Thanks for an amazing plugin and tutorial! I just wondering if there is a way to repeat a event. Eg: Weekly/daily repeat!?!

    Thanks for you support!

    Jonathan

  • Charles

    This is awesome. Anyone want to make a plugin out of it?

  • Leannekera

    As Zech asked back in February where do I put this code? Is it all ment to go in functions.php?

    Can we have a demo of the shortcode please. Is there anyway we can use shortcodes for our themes.

    Please do not reference me to some other site I have been hunting for the answer for hours and I’m grumpy lol

  • Leannekera

    As Zech asked back in February where do I put this code? Is it all ment to go in functions.php? I have tired this but it breaks the site :(

    Can we have a demo of the shortcode please. Is there anyway we can use shortcodes for our themes? I am trying to build this as a seperate template however I’m having no luck at all.

    Please do not reference me to some other site I have been hunting for the answer for hours and I’m very grumpy. grrrr! lol

  • Leannekera

    Ignore the narky cow she has it working!

    Few… Now to buy a wig for all that hair pulling :p

    Thank you so much for this Noel, maybe worth putting together a quick and dirty twentyten working theme for noobs such as myself.

  • Anonymous

    Hi Noel ty for your tutorial. I have only one issue that is related with wpml and the manual database query.
    Question is there a way to achieve the same results in $querystr but using only WordPress API calls and not manually query the database (otherwise wpml wont display my other languages in the results).

    Regards

  • http://twitter.com/design_shuffle Dan Collins

    pretty dam cool this man! thank you for the time taken demonstrating this, it will come in handy!

  • leannekera

    Im having the same issue with WordPress 3.2.1, Noel are there any updates I’m missing?

  • leannekera

    Tejas I think your after this mate :

    Replace –
    // – determine if it’s a new day –
    $longdate = date(“l, F j, Y”, $sd);
    if ($daycheck == null) { echo ” . $longdate . ”; }
    if ($daycheck != $longdate && $daycheck != null) { echo ” . $longdate . ”; }

    With –
    // – determine if it’s a new day –
    $longdate = date(“l, F j, Y”, $sd);
    $enddate = date(“l, F j, Y”, $ed);
    if ($daycheck == null) { echo ” . $longdate . $enddate .”; }
    if ($daycheck != $longdate && $daycheck != null) { echo ” . $longdate . ”; }

  • leannekera

    Managed to fix this by removing all gaps from pubforce-admin.js

  • Don

    I think I found an error in the SQL code. You are calling the postmeta twice, however, you are giving them the same name. The second ‘tf_events_enddate’ needs to actually be ‘tf_events_startdate’ for the events to be sorted by start time.

  • http://www.noeltock.com Noel

    @ don, yep! Haven’t updated the file in a while, probably need to do that for 3.3 again. Cheers!

    @ 262media, there is now, just replace the old query.

    @ jonathan, not easily :)

    @ flo, You’re right, it’s something we ended up fixing later on, thanks for clearing that up for other users.

    @ frances, the loop is certainly separate, it’s contained in the SELECT statement at the top. However, with 3.1 and beyond, you can solve this query using WP functions now.

    @ miguel, that’s quite a broad question, likely that the way it’s included in the PHP isn’t working out.

    @ vezu, pleasure!

    @ henning, you’d need to amend the query or add a variable to the shortcode.

    @ brian, no tutorial for that yet, though it wouldn’t look too much different from this. This is how we’ve solved custom post types ( http://www.noeltock.com/web-design/wordpress/custom-post-types-are-not-posts/ ). Featured events in this case do have a different shortcode, just look at the function to see how you’ve defined it.

  • Yachzo

    Hey Noel this is great. I am trying to link each event listing to a single post so when you click on the title from the list it takes you to an expanded page on the event. I can get the description easy enough, but I can’t seem to get the date working properly. It displays as Thursday, January 1, 1970. The date on the archive list is correct though. Just hoping you could shed some light on a proper way to output single event date.

  • Simondavidmelhuish

    Is there any way we can use the code to paginate results over a certain ammount? Any ideas anyone?

  • Jon Masterson

    Want to do the same thing… not sure how to accomplish it.

  • http://allenmoore.me Allen Moore

    Is there a way to use the get_permalink option to link to a page for each event?

  • Andy

    I’m crazy new to custom posts and don’t know what to do with the files provided here. Would love to be able to replicate something very similar to whats here with events. Can anyone tell me whats needs to be done with the files provided?

    Thanks in advance!

  • http://twitter.com/patrickedqvist Patrick Edqvist

    Hi Noel,

    Sorry for being such an amateur but i need some help with the query’s.

    I’ve successfully divided two loops, one to show the featured events and one to show the rest. However my problem is that the featured event is also fetched in the second query. So how can i get featured events to be excluded from the second query?

    Also if you (or someone else?) were able to write a WP_Query to replicate these query’s it would probably save my project endless amount of time.

    Hope you can help me solve this!

    Regards,Patrick

  • http://gregoryamcmullen.com/ Gregory A McMullen

    The way I did it was by using the shortcode (and editing it)

    In the if(strlen($post->post_content) area, edit the “…” section and use ‘…;

    The way mine is setup, it provides a link ONLY if it’s beyond the description length, which is 150 chars.

    Hope this helps!

  • Keisa

    Would you mind adding the file in which we add these codes to for beginners please?

  • Akeisa

    Would it be possible to add “Location”,”Ticket Price” and even a map? Any tutorials on these features to guide me?

  • Keisa

    Also, is there anyway to make events search engine friendly? So when a viewer types in “San Diego” to see if an Artist is performing in that city, ALL events for San Diego would end up in search results…Is this possible?

  • Keisa

    One last request…any possible way to rearrange the Full Date , Title, Time ect? I managed to rearrange the time and description but I can’t figure out how to remove the Title from it’s current position and place it on top of the Full Date.

  • Keisa

    Can you create a tutorial to add more columns with custom text fields? For example “Ticket Price” $12.00 and on the column of the events post type each event has the ticket price within the column.

    And perhaps a tutorial to add and display new fields within post and edit screen. //Ticket Price, Location, Venue Phone…I tried to add them myself by copying a few codes but of course…unsuccessful.

  • Keisa

    How exactly can we turn this into a widget?

  • John

    Great work – just stumbled on this and plan on using it in a project I’m working on. Thanks for sharing!

  • John

    Any way you could repost that, Gregory? The pastebin link isn’t working for me.

  • http://gregoryamcmullen.com/ Gregory A McMullen

    I believe this is the line that you’ll need to look for.

    post_content) > $description) { echo substr($post->post_content, 0, $description) . ‘…more details‘; } else { echo $post->post_content; } ?>

  • John

    Cool thanks – I was actually hoping to steal a piece of your post type and hopefully figure out how you would extract the date from it :). I can get the date back of course, but it’s in the linux format (1122334456) or whatever…not the ‘pretty’ date format (ie January 26, 2013) that you get by using the shortcode to do it. Can’t quite figure it out using my template opposed to the shortcode.

  • http://gregoryamcmullen.com/ Gregory A McMullen

    Here is what I used for the short code with a screen shot of the widget + short code output (built into the theme, but accessible through a text widget as well).

    http://gregoryamcmullen.com/coding/events

    Good luck, and hope this helps!

  • John

    Thanks man – unfortunately no luck. Can’t figure out how to display this stuff on a single post. Works great in the template for a list of events, but I need to display a single event on its own page (ie event-single.php) but haven’t found a way to do it with a properly formatted date display.

  • http://gregoryamcmullen.com/ Gregory A McMullen

    Okay! Give me some time. I think I have what you want. I was just misinterpreting you.

  • John

    You know what I JUST figured it out. Just my limited php knowledge not understanding how to spin the date as I needed in the single.php file basically.

    Essentially I had a developer friend help me out and came up with this simpleness in my template file :)

    “$mydate = get_post_meta($post->ID, “tf_events_startdate”, true);”
    ” php echo date(“M d Y”, $mydate); >”

    Thanks much for your help though, Gregory!

  • http://gregoryamcmullen.com/ Gregory A McMullen

    That’s great news! Glad you have it figured out. Happy to help. If I did, of course :).

  • Peter

    I am using events that do not span over more than one day. Can anyone point me to a way to easily create a calendar of events for this custom post type?

  • Paul

    Hi,

    Loving the work here as it has done pretty much exactly what I was hoping to achieve. The only thing that isn’t working as hoped is the order these events display in. They seem to be displayed in order of being added and not by the dates of the events i.e. event closest to happen.

    Is there a way to achieve this as I’ve been trying for a while now but my PHP knowledge is holding me back

    Thanks

  • deepak kumar

    nice blog…

  • Cleo Henderson

    Okay so I’m trying to get the shortcode to pull a specific category. So here’s what I did, any ideas?!

  • Cleo Henderson

    Im having the same issue.

  • Cleo Henderson

    LOL, never mind. I didn’t have any within the current date range.