How to get a list of all events in the given language of the page
-
Hello
I am using the commercial Hotec theme (themeforest). It comes with its own custom post type called “events” and the shortcode “[events]” that displays a list of all them in a page.
xili-language is running well in the system and can translate the “events”. I have a translation for every event. Language switcher works.
I would like the shortcode to display only the events that have the same language of the page the shortcode runs in. As I have very little php and wordpress programming experience, I desperately need help with this. I searched on the xili wiki but could not find anything.
can you please help?
thanksThe code for the [events] shortcode :
function st_events_func( $atts, $content='' ) { global $wp_query; global $post, $paged; $tmp_post = $post; extract( shortcode_atts( array( 'title' => '', 'cats' => '', 'numpost'=>5, 'exclude'=>'', 'orderby'=>'_st_event_start_date', 'order'=>'DESC', 'pbwith'=>'1_1', 'type'=>1, 'site_layout'=>'', 'show_title'=>'n', 'show_paging'=>'n' ), $atts ) ); // $wc = $builder[$i]['pbwith']; old $wc = $pbwith; // new $w= explode('_',$wc); $t = intval($w[0]); $m = intval($w[1]); if($m>0 and $t>0){ $c = $t/$m; }else{ $c=1; } $html =''; // just only for one cate if(is_string($cats)){ $cats = explode(',',$cats); } if( $title!=''){ $html .= '<div class="builder-title-wrapper clearfix"> <h3 class="builder-item-title">'.esc_html($title).'</h3> </div>'; } if(intval($numpost)<=0){ $numpost = (int) get_option('posts_per_page',10); }else{ $numpost = intval($numpost); } $args = array( 'posts_per_page' => $numpost ); if($cats>0){ // $args['category__in'] = array($cats); } if($exclude!=''){ $exclude= explode(',',$exclude); $args['post__not_in'] = $exclude; } if($orderby=='_st_event_start_date' || $orderby=='_st_event_end_date'){ $args['meta_key'] = $orderby; $args['meta_query'] = array( array( 'key' => $orderby, 'value'=>'1000-01-01 00:00', 'compare'=>'>=', 'type' => 'DATETIME', ) ); $args['orderby'] = 'meta_value'; }else{ $args['orderby'] = $orderby; } $args['order'] = $order; $args['post_type'] = 'event'; if($paged>0){ $args['paged'] = $paged; }else{ $paged = isset($_REQUEST['paged']) ? intval($_REQUEST['paged']) : 1; } // added in ver 1.3 if(st_is_wpml()){ $args['sippress_filters'] = true; $args['language'] = get_bloginfo('language'); } $new_query = new WP_Query($args); $myposts = $new_query->posts; $e = ''; $template_file = ST_TEMPLATE_DIR.'loop/loop-event.php'; // display as list foreach( $myposts as $post ) : setup_postdata($post); $e.=st_get_content($template_file); $i++; endforeach; $html .=$e; $p =''; if(!is_home() && !is_front_page()) { // only true if not is home page or front page if($show_paging=='y'){ $p = st_post_pagination($new_query->max_num_pages,2, false); if($p!=''){ $p = '<div class="pagination text-center t0">'.$p.'</div>'; } } } wp_reset_postdata(); return '<div class="loop-events">'.do_shortcode($html).$p.'</div>'; } add_shortcode( 'events', 'st_events_func' );
- The topic ‘How to get a list of all events in the given language of the page’ is closed to new replies.