I'm working in inbound marketing company and they use X theme.co theme.
the site has 2 languages hebrew and english. I'm trying to make a shortcode to add the previous events using Ajax and Functions.php. While I'm logged in the site know how to detect whether it's english or hebrew. but when I'm logged out the site will give me the main language which is hebrew. by the way there are hebrew events and english events ,it's not the same db. and When you first go to events page it will detect the language but won't detect it after you click the "add more events" which will activate the function in functions.php
I don't know why its acting like that. please help!
function load_events_by_ajax_callback(){
check_ajax_referer('load_more_events','security');
$paged = $_POST['page'];
//Years
$prev_year=$_POST['cos_prev_year'];
$curr_year=$_POST['cos_curr_year'];
//Years
$all_events="";
global $post;
$args = array(
'post_type' => 'event',
'meta_key' => '_event_date',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => '12',
'paged' => $paged,
'meta_query' => array(
array(
'key' => '_event_date',
'type' => 'numeric',
),
)
);
$featured_query = new WP_Query( $args );
if( $featured_query->have_posts() ):
while( $featured_query->have_posts() ) : $featured_query->the_post();
$date = get_field('_event_date');
$get_the_date=date_parse_from_format("d.m.Y", $date);
$display_date=$get_the_date["year"].'/'.$get_the_date["month"].'/'.$get_the_date["day"];
$month=$get_the_date["month"];
$month_name=date('F', mktime(0, 0, 0, $month, 10));
$img_url=get_the_post_thumbnail_url(null,'large');
//Years
$curr_year=$get_the_date["day"];
$dt = DateTime::createFromFormat('y',$curr_year);
$curr_year=$dt->format('Y');
if($curr_year != $prev_year){
$all_events.='<h5 class="h-custom-headline cs-ta-center h5 accent"><span>'.$curr_year.'</span></h5>';
$prev_year=$curr_year;
}
//Years
$all_events.='<div class="novus_ptBMtYhoMB317wduyTDqor0Ys x-column x-sm cs-ta-center x-1-3" style="margin:1% !important; float:none !important; display:inline-block !important; vertical-align:top !important;" >';
$all_events.='<div class="x-recent-posts cf horizontal">';
$all_events.='<a class="x-recent-post1 with-image " href="'.get_permalink($post->ID).'">';
$all_events.='<article class="event type-event status-publish has-post-thumbnail hentry ">';
$all_events.='<div class="entry-wrap">';
//Start - date of the event
if(time()>strtotime($date)){
$all_events.='<div style="background:rgba(128,128,128,0.7) !important;" class="shortcode_event_date">';
$all_events.='<i class="fa fa-calendar" aria-hidden="true"></i>';
if(ICL_LANGUAGE_CODE == 'he'){
$all_events.='<span class="title"> אירוע הסתיים </span>';
}
else if(ICL_LANGUAGE_CODE == 'en'){
$all_events.='<span class="title"> Event ended </span>';
}
$all_events.='</div>';
}
else{
$all_events.='<div style="background:rgba(37,206,190, 0.8) !important;" class="shortcode_event_date">';
$all_events.='<i class="fa fa-calendar" aria-hidden="true"></i>';
$all_events.='<span class="date"> '.$display_date.' </span>';
$all_events.='</div>';
}
//End - date of the event
$all_events.='<div class="x-recent-posts-img" style="background-image: url('.$img_url.');"> </div>';
$all_events.='<div class="x-recent-posts-content">';
$all_events.='<h3 class="h-recent-posts">'.get_the_title().'</h3>';
$all_events.='</div>';
$all_events.="</div>";
$all_events.='</article>';
$all_events.='</a>';
$all_events.='</div>';
$all_events.="</div>";
endwhile;
endif; wp_reset_query();
//Years
$all_events.='<script>';
$all_events.='jQuery(document).ready(function($){';
$all_events.='$("#curr-year").val("'.$curr_year.'");';
$all_events.='$("#prev-year").val("'.$prev_year.'");';
$all_events.='});';
$all_events.='</script>';
//Years
echo $all_events;
wp_die();
}
found the answer here! Enable Ajax filtering in WPML