OK, I managed to make it work, here’s how i did :
Jquery part :
jQuery(".post-link").click(function(){
var post_id = jQuery(this).data('id');
jQuery.post(
ajaxurl,
{
'action': 'load_post_content',
'the_ID': post_id
},
function(response){
jQuery('#the-post-content').html(response);
}
);
return false;
});
And the function.php part :
add_action( 'wp_ajax_load_post_content', 'load_post_content' );
add_action( 'wp_ajax_nopriv_load_post_content', 'load_post_content' );
function load_post_content() {
$the_post_id = $_POST['the_ID'];
$args = array(
'post_type' => 'post',
'p' => $the_post_id
);
$ajax_query = new WP_Query($args);
$the_content;
if ( $ajax_query->have_posts() ) : while ( $ajax_query->have_posts() ) : $ajax_query->the_post();
$the_content = the_content();
endwhile;
endif;
echo $the_content;
wp_reset_postdata();
die();
}
Hope it can help !