RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.67%*) • Fixed: 5.39% (6.67%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Display WordPress Meetups With Shortcode or a PHP Function

Display WordPress Meetups With Shortcode or a PHP Function

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:

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
<?php 
2
/*
3
 Display WordPress Meetups With a Shortcode or PHP Function
4
 http://www.beliefmedia.com/wordpress-meetups
5
*/
6
 
7
function beliefmedia_wordpress_meetups($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'location' => 'Australia',
11
    'dateformat' => 'D jS M Y g:iA',
12
    'number' => '10',
13
    'offline' => 'Data temporarily offline. Check back shortly.',
14
    'cache_temp' => 1200, /* If API offline */
15
    'cache' => 3600 * 24
16
  ), $atts);
17
 
18
 $transient = 'bmwpm_' . md5(serialize($atts));
19
 $cachedposts = get_transient($transient);
20
 
21
  if ($cachedposts !== false) {
22
  $return = $cachedposts;
23
 
24
  } else {
25
 
26
    /* Get meetup JSON */
27
    $data = file_get_contents('https://api.wordpress.org/events/1.0/?location=' . $atts['location'] . '&number=' . $atts['number']);
28
 
29
    if ($data !== false) {
30
 
31
        $data = json_decode($data, true);
32
        $meetups = $data['events'];
33
 
34
           /* Number scheduled */
35
           $num = count($meetups);
36
 
37
              if ($num == 0) {
38
 
39
                 $result = '<li>No meetups in ' . $atts['location'] . ' currently scheduled.</li>';
40
 
41
              } else {
42
 
43
                 /* Build list items */
44
                 foreach ($meetups AS $meetup) {
45
 
46
                    $result .= '<li><span style=&quot;font-weight: bold;&quot;><a href=&quot;' . $meetup['meetup_url'] . '&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;>' . $meetup['title'] . '</a></span>, ' . date($atts['dateformat'], strtotime($meetup['date'])) . '<br>';
47
                    $result .= '<span style=&quot;font-size: 0.9em; font-weight: bold;&quot;>' . $meetup['meetup'] . '</span>. <span style=&quot;font-size: 0.9em;&quot;>' . $meetup['location']['location'] . ' [ <a href=&quot;http://maps.google.com/maps?z=12&t=m&q=loc:' . $meetup['location']['latitude'] . '+' . $meetup['location']['longitude'] . '&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;>MAP</a> ]</span>';
48
                    $result .= '</li>';
49
 
50
                 }
51
 
52
              }
53
 
54
        $return = '<ul>' . $result . '</ul>';
55
        set_transient($transient, $return, $atts['cache']);
56
 
57
    } else {
58
 
59
      /* If WP, not responsing, set short cache period with error message */
60
      $return = '<ul><li>' . $atts['offline'] . '</li></ul>';
61
      set_transient($transient, $return, $atts['cache_temp']);
62
 
63
    }
64
  }
65
 
66
 return $return;
67
}
68
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

You must specify a location. To determine if the location is supported by WordPress' system, simply query the API in your browser with your location of choice. The location of Sydney and Australia both work for us.

dateformat

If our date formatting isn't to your liking, alter it in the shortcode function or as an attribute. Alter by way of PHP's date() formatting.

number

If not defined, the API will return 10 results. Alter with number="20".

offline

If the WordPress API is offline, we'll display this message.

cache_temp

If the WordPress API is offline, we'll wait cache_temp before trying again. In the meantime, the above message will be displayed.

cache

The 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
<?php 
2
<?php
3
/*
4
 Display WordPress Meetups With a Shortcode or PHP Function
5
 http://www.beliefmedia.com/wordpress-meetups
6
*/
7
 
8
function beliefmedia_wordpress_meetups($location = 'Australia', $args = '') {
9
 
10
  $atts = array(
11
    'dateformat' => 'D jS M Y g:iA',
12
    'number' => '10',
13
    'cache' => 3600 * 24
14
  );
15
 
16
 /* Merge $args with $atts */
17
 $atts = (empty($args)) ? $atts : array_merge($atts, $args);
18
 
19
 /* For caching */
20
 $atts['location'] = $location;
21
 
22
 $transient = 'bm_wordpres_meets_' . md5(serialize($atts));
23
 $cachedposts = beliefmedia_get_transient($transient, $atts['cache']);
24
 
25
  if ($cachedposts !== false) {
26
  $return = $cachedposts;
27
 
28
  } else {
29
 
30
    /* Get meetup JSON */
31
    $data = file_get_contents('https://api.wordpress.org/events/1.0/?location=' . $atts['location'] . '&number=' . $atts['number']);
32
 
33
    if ($data !== false) {
34
 
35
        $data = json_decode($data, true);
36
        $meetups = $data['events'];
37
 
38
           /* Number scheduled */
39
           $num = count($meetups);
40
 
41
              if ($num == 0) {
42
 
43
                 $result = '<li>No meetups in ' . $atts['location'] . ' currently scheduled.</li>';
44
 
45
              } else {
46
 
47
                 /* Build list items */
48
                 foreach ($meetups AS $meetup) {
49
 
50
                    $result .= '<li><span style=&quot;font-weight: bold;&quot;><a href=&quot;' . $meetup['meetup_url'] . '&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;>' . $meetup['title'] . '</a></span>, ' . date($atts['dateformat'], strtotime($meetup['date'])) . '<br>';
51
                    $result .= '<span style=&quot;font-size: 0.9em; font-weight: bold;&quot;>' . $meetup['meetup'] . '</span>. <span style=&quot;font-size: 0.9em;&quot;>' . $meetup['location']['location'] . ' [ <a href=&quot;http://maps.google.com/maps?z=12&t=m&q=loc:' . $meetup['location']['latitude'] . '+' . $meetup['location']['longitude'] . '&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;>MAP</a> ]</span>';
52
                    $result .= '</li>';
53
 
54
                 }
55
 
56
              }
57
 
58
        $return = '<ul>' . $result . '</ul>';
59
        beliefmedia_set_transient($transient, $return);
60
 
61
    } else {
62
 
63
      /* If WP, not responsing... */
64
      $return = beliefmedia_get_transient_data($transient);
65
 
66
    }
67
  }
68
 
69
 return $return;
70
}
71
 
72
/* Usage */
73
echo beliefmedia_wordpress_meetups($loc = 'Australia');
74
?>

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.
Display WordPress Meetups With Shortcode or a PHP Function

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


Title: Display WordPress Meetups (WP Plugin)
Description: Display WordPress Meetups With a Shortcode or PHP Function. Renders WordPress meetups in a specific area. Results are cached for 24 hours.
  Download • Version 0.1, 1.9K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (1.1K)    PHP Code & Snippets, (1.1K)    

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment