Hi !
I created an ajax slider on a home page. On click to “next” button, an ajax function retrieve the content of a custom post type, and display it with FLBuilder::render_query.
But FLBuilder::render_query return nothing.
I test with the shortcode too, but nothing appears.
I got the right post_id from the js.
The JS :
$.ajax({ // you can also use $.post here
url : mahii_carousel_params.ajaxurl, // AJAX handler
data : data,
type : 'POST',
success : function( data ){
if( data ) {
setTimeout(function(){
container.empty().append(data);
container.animate({
opacity: 1,
left: 0,
}, 400);
if( $('.fl-ajax-carousel').find('.fl-heuritech-tab-title-active').length > 0 ) {
$('.fl-ajax-carousel').find('.fl-heuritech-tab-title-active').trigger('mouseenter');
}
}, 300);
}
else {
console.log('no data');
}
}
});
// Carousel
function mahii_carousel_ajax_handler(){
$current_number = $_POST['current'];
$minPos = $_POST['min'];
if($minPos < 0) {
$minPos = $_POST['min'] * -1;
}
$current_numberPos = $current_number + $minPos;
$maxPos = $_POST['max']+$minPos;
$percent = $current_numberPos * 100 / $maxPos;
$args = array(
'post_type' => 'slider-heuritech',
'tax_query' => array(
array(
'taxonomy' => 'slider-category',
'field' => 'slug',
'terms' => $_POST['category'],
),
),
'meta_key' => 'place',
'meta_value' => $current_number,
'posts_per_page' => 1,
);
$carousel = new WP_Query( $args );
if( $carousel->have_posts() ) : while( $carousel->have_posts() ) : $carousel->the_post();
$post_ID = get_the_ID();
$current = get_field('place');
if(get_field('dark_ui')) {
$dark = " dark-ui";
}
endwhile;
endif;
wp_reset_query();
echo '<svg class="fl-ajax-carousel-prev'.$dark.'" id="prev-slide" data-current="'.$current.'" data-max="'.$_POST['max'].'" data-min="'.$_POST['min'].'" viewbox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.717.357L.919 16.154 16.717 31.95" stroke="#fff" stroke-linejoin="round"/></svg>';
FLBuilder::render_query( array(
'post_type' => 'slider-heuritech',
'p' => $post_ID,
));
echo do_shortcode('[fl_builder_insert_layout id="'.$post_ID.'"]');
die;
}
add_action('wp_ajax_carousel', 'mahii_carousel_ajax_handler'); // wp_ajax_{action}
add_action('wp_ajax_nopriv_carousel', 'mahii_carousel_ajax_handler'); // wp_ajax_nopriv_{action}
No error on the page nor in the XHR.
Someone can help me with this ?