
There’s a group of committed WordPress enthusiasts, bloggers, and developers that get together in most cities around the world for regular meetups. They group talks about their WordPress projects, list to guest speakers, and build upon features for the WP core. While I’ve never attended a local meet (partly because we have so many of our own), I’m keen to attend one in the future. To ensure I keep abreast of future dates, we built a little shortcode (utilizing the WP API ) that will render upcoming meets into a WordPress post or page.
We’ve listed Australian and local Sydney meets on a reference page. The shortcode on this website will permit you to do the same.
The Result
The next 5 meets in Sydney can be rendered with the shortcode of [wpmeets number="5" location="Sydney"]
. The result:
- 14 Things You Must Do Before Launching A Website, Mon 25th Feb 2019 6:00PM
WordPress Sydney. Sydney, Australia [ MAP ] - Parramatta WordPress Meetup: TBA, Mon 4th Mar 2019 6:00PM
WordPress Sydney. Parramatta, Australia [ MAP ] - Essential Design Tips for Beaver Builder & Automating Social with IFTTT, Mon 25th Mar 2019 6:00PM
WordPress Sydney. Sydney, Australia [ MAP ] - Parramatta WordPress Meetup: TBA, Mon 1st Apr 2019 6:00PM
WordPress Sydney. Parramatta, Australia [ MAP ] - SEO Tips and Tricks, Mon 29th Apr 2019 6:00PM
WordPress Sydney. Sydney, Australia [ MAP ]
WordPress Shortcode
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/* Display WordPress Meetups With a Shortcode or PHP Function http://www.beliefmedia.com/wordpress-meetups */ function beliefmedia_wordpress_meetups($atts) { $atts = shortcode_atts(array( 'location' => 'Australia', 'dateformat' => 'D jS M Y g:iA', 'number' => '10', 'offline' => 'Data temporarily offline. Check back shortly.', 'cache_temp' => 1200, /* If API offline */ 'cache' => 3600 * 24 ), $atts); $transient = 'bmwpm_' . md5(serialize($atts)); $cachedposts = get_transient($transient); if ($cachedposts !== false) { $return = $cachedposts; } else { /* Get meetup JSON */ $data = file_get_contents('https://api.wordpress.org/events/1.0/?location=' . $atts['location'] . '&number=' . $atts['number']); if ($data !== false) { $data = json_decode($data, true); $meetups = $data['events']; /* Number scheduled */ $num = count($meetups); if ($num == 0) { $result = '<li>No meetups in ' . $atts['location'] . ' currently scheduled.</li>'; } else { /* Build list items */ foreach ($meetups AS $meetup) { $result .= '<li><span style="font-weight: bold;"><a href="' . $meetup['meetup_url'] . '" target="_blank">' . $meetup['title'] . '</a></span>, ' . date($atts['dateformat'], strtotime($meetup['date'])) . '<br>'; $result .= '<span style="font-size: 0.9em; font-weight: bold;">' . $meetup['meetup'] . '</span>. <span style="font-size: 0.9em;">' . $meetup['location']['location'] . ' [ <a href="http://maps.google.com/maps?z=12&t=m&q=loc:' . $meetup['location']['latitude'] . '+' . $meetup['location']['longitude'] . '" target="_blank">MAP</a> ]</span>'; $result .= '</li>'; } } $return = '<ul>' . $result . '</ul>'; set_transient($transient, $return, $atts['cache']); } else { /* If WP, not responsing, set short cache period with error message */ $return = '<ul><li>' . $atts['offline'] . '</li></ul>'; set_transient($transient, $return, $atts['cache_temp']); } } return $return; } add_shortcode('wpmeets','beliefmedia_wordpress_meetups'); |
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
Shortcode Attributes
The following shortcode attributes are available.
location

Sydney
and Australia
both work for us.dateformat

number
number="20"
.offline
cache_temp
cache_temp
before trying again. In the meantime, the above message will be displayed.cache
cache
period is the time to cache results. We cache for 24 hours by default.PHP Function
Used outside of WordPress, the following function may be used. Usage requires Simple Cache. Other than the location, arguments are passed to the function in an array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
<?php /* Display WordPress Meetups With a Shortcode or PHP Function http://www.beliefmedia.com/wordpress-meetups */ function beliefmedia_wordpress_meetups($location = 'Australia', $args = '') { $atts = array( 'dateformat' => 'D jS M Y g:iA', 'number' => '10', 'cache' => 3600 * 24 ); /* Merge $args with $atts */ $atts = (empty($args)) ? $atts : array_merge($atts, $args); /* For caching */ $atts['location'] = $location; $transient = 'bm_wordpres_meets_' . md5(serialize($atts)); $cachedposts = beliefmedia_get_transient($transient, $atts['cache']); if ($cachedposts !== false) { $return = $cachedposts; } else { /* Get meetup JSON */ $data = file_get_contents('https://api.wordpress.org/events/1.0/?location=' . $atts['location'] . '&number=' . $atts['number']); if ($data !== false) { $data = json_decode($data, true); $meetups = $data['events']; /* Number scheduled */ $num = count($meetups); if ($num == 0) { $result = '<li>No meetups in ' . $atts['location'] . ' currently scheduled.</li>'; } else { /* Build list items */ foreach ($meetups AS $meetup) { $result .= '<li><span style="font-weight: bold;"><a href="' . $meetup['meetup_url'] . '" target="_blank">' . $meetup['title'] . '</a></span>, ' . date($atts['dateformat'], strtotime($meetup['date'])) . '<br>'; $result .= '<span style="font-size: 0.9em; font-weight: bold;">' . $meetup['meetup'] . '</span>. <span style="font-size: 0.9em;">' . $meetup['location']['location'] . ' [ <a href="http://maps.google.com/maps?z=12&t=m&q=loc:' . $meetup['location']['latitude'] . '+' . $meetup['location']['longitude'] . '" target="_blank">MAP</a> ]</span>'; $result .= '</li>'; } } $return = '<ul>' . $result . '</ul>'; beliefmedia_set_transient($transient, $return); } else { /* If WP, not responsing... */ $return = beliefmedia_get_transient_data($transient); } } return $return; } /* Usage */ echo beliefmedia_wordpress_meetups($loc = 'Australia'); ?> |
Considerations
- WordPress lists API examples as listed below. Because you can search by geographical coordinates, you might consider applying our IP to location API and rendering results for specific locales, or resolving to the region or country level.
https://api.wordpress.org/events/1.0
https://api.wordpress.org/events/1.0/?number=3
https://api.wordpress.org/events/1.0/?location=Seattle
https://api.wordpress.org/events/1.0/?location=Australia
https://api.wordpress.org/events/1.0/?latitude=51.051&longitude=13.738
https://api.wordpress.org/events/1.0/?ip=136.0.16.1
https://api.wordpress.org/events/1.0/?country=IT
- Since this article was written, WordPress has released V4.8 of the platform. The dashboard now includes local meets by default.
Meetups displayed in the WP Dashboard.
- It’s likely we’ve missed various meetup types (camps, etc- not that it really matters). When they’re shown we’ll update the shortcode.
Download
Shortt URL for this post: http://shor.tt/17M5