Below, you’ll find a detailed guide on how to add the Import Social Events Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Import Social Events Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Import Social Events Plugin and the shortcodes it provides:

"Import Social Events is a WordPress plugin that seamlessly integrates your social events from Facebook into your website, ensuring your audiences never miss an update."
- [facebook_events]
Import Social Events [facebook_events] Shortcode
The Import Facebook Events plugin shortcode enables users to display Facebook events on their website. It includes attributes for layout, post per page, category, past events, order, and date range.
Shortcode: [facebook_events]
Parameters
Here is a list of all possible facebook_events shortcode parameters and attributes:
layout
– defines the layout style for the eventscol
– sets the number of columns for the events layoutposts_per_page
– determines the number of events displayed per pagecategory
– allows filtering of events by specific categoriespast_events
– enables display of past events when set to “yes”order
– sets the ordering of events, either descending or ascendingorderby
– determines the parameter to order events bystart_date
– sets the start date for events to be displayedend_date
– sets the end date for events to be displayed
Examples and Usage
Basic example – Display Facebook events using the default parameters set in the plugin settings.
[facebook_events]
Advanced examples
Display Facebook events in a specific layout, with a specified number of posts per page, and from specific categories.
[facebook_events layout="style2" col='2' posts_per_page='12' category="cat1,cat2"]
Show past Facebook events in descending order.
[facebook_events past_events="yes" order="desc"]
Display Facebook events that fall within a specific date range.
[facebook_events start_date="2022-01-01" end_date="2022-12-31"]
Show Facebook events from a specific category, ordered by the event start date in ascending order.
[facebook_events category="cat1" orderby="event_start_date" order="asc"]
PHP Function Code
In case you have difficulties debugging what causing issues with [facebook_events]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'facebook_events', array( $this, 'facebook_events_archive' ) );
Shortcode PHP function:
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | function facebook_events_archive( $atts = array () ) { // phpcs:ignore Squiz.PHP.CommentedOutCode.Found // [facebook_events layout="style2" col='2' posts_per_page='12' category="cat1,cat2" past_events="yes" order="desc" orderby="" start_date="" end_date="" ] $current_date = current_time( 'timestamp' ); $paged = ( get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 ); if ( is_front_page() ) { $paged = ( get_query_var( 'page' ) ? get_query_var( 'page' ) : 1 ); } $eve_args = array ( 'post_type' => 'facebook_events' , 'post_status' => 'publish' , 'meta_key' => 'start_ts' , // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key --Ignore. 'paged' => $paged , ); // post per page. if ( isset( $atts [ 'posts_per_page' ] ) && ! empty ( $atts [ 'posts_per_page' ] ) && is_numeric ( $atts [ 'posts_per_page' ] ) ) { $eve_args [ 'posts_per_page' ] = $atts [ 'posts_per_page' ]; } // Past Events. if ( ( isset( $atts [ 'start_date' ] ) && ! empty ( $atts [ 'start_date' ] ) ) || ( isset( $atts [ 'end_date' ] ) && ! empty ( $atts [ 'end_date' ] ) ) ) { $start_date_str = '' ; $end_date_str = '' ; if ( isset( $atts [ 'start_date' ] ) && ! empty ( $atts [ 'start_date' ] ) ) { try { $start_date_str = strtotime ( sanitize_text_field( $atts [ 'start_date' ] ) ); } catch ( Exception $e ) { $start_date_str = '' ; } } if ( isset( $atts [ 'end_date' ] ) && ! empty ( $atts [ 'end_date' ] ) ) { try { $end_date_str = strtotime ( sanitize_text_field( $atts [ 'end_date' ] ) ); } catch ( Exception $e ) { $end_date_str = '' ; } } if ( ! empty ( $start_date_str ) && ! empty ( $end_date_str ) ) { $eve_args [ 'meta_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query 'relation' => 'AND' , array ( 'key' => 'end_ts' , 'compare' => '>=' , 'value' => $start_date_str , ), array ( 'key' => 'end_ts' , 'compare' => '<=' , 'value' => $end_date_str , ), ); } elseif ( ! empty ( $start_date_str ) ) { $eve_args [ 'meta_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array ( 'key' => 'end_ts' , 'compare' => '>=' , 'value' => $start_date_str , ), ); } elseif ( ! empty ( $end_date_str ) ) { $eve_args [ 'meta_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query 'relation' => 'AND' , array ( 'key' => 'end_ts' , 'compare' => '>=' , 'value' => strtotime ( date ( 'Y-m-d' ) ), ), array ( 'key' => 'end_ts' , 'compare' => '<=' , 'value' => $end_date_str , ), ); } } else { if ( isset( $atts [ 'past_events' ] ) && $atts [ 'past_events' ] === true ){ $atts [ 'past_events' ] = "yes" ; } if ( isset( $atts [ 'past_events' ] ) && 'yes' === $atts [ 'past_events' ] ) { $eve_args [ 'meta_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array ( 'key' => 'end_ts' , 'compare' => '<=' , 'value' => $current_date , ), ); } else { $eve_args [ 'meta_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array ( 'key' => 'end_ts' , 'compare' => '>=' , 'value' => $current_date , ), ); } } // Category. if ( isset( $atts [ 'category' ] ) && ! empty ( $atts [ 'category' ] ) ) { $categories = explode ( ',' , $atts [ 'category' ] ); $tax_field = 'slug' ; if ( is_numeric ( implode( '' , $categories ) ) ) { $tax_field = 'term_id' ; } if ( ! empty ( $categories ) ) { $eve_args [ 'tax_query' ] = array ( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query array ( 'taxonomy' => $this ->event_category, 'field' => $tax_field , 'terms' => $categories , ), ); } } // Order by. if ( isset( $atts [ 'orderby' ] ) && ! empty ( $atts [ 'orderby' ] ) ) { if ( 'event_start_date' === $atts [ 'orderby' ] || 'event_end_date' === $atts [ 'orderby' ] ) { if ( 'event_end_date' === $atts [ 'orderby' ] ) { $eve_args [ 'meta_key' ] = 'end_ts' ; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key --Ignore. } $eve_args [ 'orderby' ] = 'meta_value' ; } else { $eve_args [ 'orderby' ] = sanitize_text_field( $atts [ 'orderby' ] ); } } else { $eve_args [ 'orderby' ] = 'meta_value' ; } // Order. if ( isset( $atts [ 'order' ] ) && ! empty ( $atts [ 'order' ] ) ) { if ( 'DESC' === strtoupper ( $atts [ 'order' ] ) || 'ASC' === strtoupper ( $atts [ 'order' ] ) ) { $eve_args [ 'order' ] = sanitize_text_field( $atts [ 'order' ] ); } } else { if ( isset( $atts [ 'past_events' ] ) && $atts [ 'past_events' ] === true ){ $atts [ 'past_events' ] = "yes" ; } if ( isset( $atts [ 'past_events' ] ) && 'yes' === $atts [ 'past_events' ] && 'meta_value' === $eve_args [ 'orderby' ] ) { $eve_args [ 'order' ] = 'DESC' ; } else { $eve_args [ 'order' ] = 'ASC' ; } } $col = 2; $css_class = 'col-ife-md-6' ; if ( isset( $atts [ 'col' ] ) && ! empty ( $atts [ 'col' ] ) && is_numeric ( $atts [ 'col' ] ) ) { $col = $atts [ 'col' ]; switch ( $col ) { case '1' : $css_class = 'col-ife-md-12' ; break ; case '2' : $css_class = 'col-ife-md-6' ; break ; case '3' : $css_class = 'col-ife-md-4' ; break ; case '4' : $css_class = 'col-ife-md-3' ; break ; default : $css_class = 'col-ife-md-4' ; break ; } } $facebook_events = new WP_Query( $eve_args ); $wp_list_events = '' ; // Start the Loop. if ( is_front_page() ) { $curr_paged = $paged ; global $paged ; $temp_paged = $paged ; $paged = $curr_paged ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } $ife_options = get_option( IFE_OPTIONS ); $accent_color = isset( $ife_options [ 'accent_color' ] ) ? $ife_options [ 'accent_color' ] : '#039ED7' ; $direct_link = isset( $ife_options [ 'direct_link' ] ) ? $ife_options [ 'direct_link' ] : 'no' ; if ( ! ife_is_pro() ) { $direct_link = 'no' ; } ob_start(); ?> <div class = "row_grid" > <?php $template_args = array (); $template_args [ 'css_class' ] = $css_class ; $template_args [ 'direct_link' ] = $direct_link ; if ( $facebook_events ->have_posts() ) : while ( $facebook_events ->have_posts() ) : $facebook_events ->the_post(); if ( isset( $atts [ 'layout' ] ) && $atts [ 'layout' ] == 'style2' && ife_is_pro() ){ get_ife_template( 'ife-archive-content2.php' , $template_args ); } else { get_ife_template( 'ife-archive-content.php' , $template_args ); } endwhile ; // End of the loop. if ( $facebook_events ->max_num_pages > 1 ) : // custom pagination. ?> <div class = "col-ife-md-12" > <nav class = "prev-next-posts" > <div class = "prev-posts-link alignright" > <?php echo get_next_posts_link( 'Next Events »' , $facebook_events ->max_num_pages ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </div> <div class = "next-posts-link alignleft" > <?php echo get_previous_posts_link( '« Previous Events' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> </div> </nav> </div> <?php endif ; else : echo esc_attr( apply_filters( 'ife_no_events_found_message' , __( 'No Events are found.' , 'import-facebook-events' ) ) ); endif ; ?> </div> <style type= "text/css" > .ife_event .event_date{ background-color: <?php echo esc_attr( $accent_color ); ?>; } .ife_event .event_desc .event_title{ color: <?php echo esc_attr( $accent_color ); ?>; } </style> <?php // Allow developers to do something here. do_action( 'ife_after_event_list' , $facebook_events ); $wp_list_events = ob_get_contents(); ob_end_clean(); wp_reset_postdata(); if ( is_front_page() ) { global $paged ; $paged = $temp_paged ; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } return $wp_list_events ; } |
Code file location:
import-facebook-events/import-facebook-events/includes/class-import-facebook-events-cpt.php
Conclusion
Now that you’ve learned how to embed the Import Social Events Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply