Hi, how can use with ajax, do you have a snippit with currently page
for example ajax_dfi(); i think maybe you already coded in plugin.
my way;
function deneme() {
if (class_exists('Dynamic_Featured_Image')) :
global $dynamic_featured_image;
// Get the current page ID from the AJAX request data
$current_page_id = isset($_POST['current_page_id']) ? intval($_POST['current_page_id']) : null;
if ($current_page_id) {
$featured_images = $dynamic_featured_image->get_featured_images($current_page_id);
if ($featured_images) :
$result = array();
foreach ($featured_images as $image) :
$result[] = $image['full'];
endforeach;
echo json_encode($result);
endif;
}
endif;
wp_die();
}
add_action( 'wp_ajax_deneme', 'deneme' );
add_action( 'wp_ajax_nopriv_deneme', 'deneme' );
index.php
<script>
jQuery(document).ready(function($) {
// Get the current page ID
var current_page_id = <?php echo get_the_ID(); ?>;
var url = '<?php echo admin_url('admin-ajax.php'); ?>';
$.ajax({
url: url,
type: 'POST',
data: {
action: 'deneme',
current_page_id: current_page_id
},
dataType: 'json',
success: function(data) {
console.log(data);
},
error: function() {
console.log('Error retrieving featured images.');
}
});
});
</script>
Hi, how can use with ajax, do you have a snippit with currently page
for example ajax_dfi(); i think maybe you already coded in plugin.
my way;
index.php