I have stored the post-id info in a data-* attribute, I wish to display this content in a div via &.ajax() function.
this is the code I'm working on.
A list item that display the post thumb
<li class="homus-partners-section-single" data-post-id="<?php the_ID(); ?>"> <?php the_post_thumbnail(); ?> </li>the div where i want to display the item
<div class="homus-partners-detalis"> <div class="homus-partners-detalis-img"> <?php the_post_thumbnail(); ?> </div> <div class="homus-partners-detalis-info"> <h4> <?php the_title(); ?> </h4> <p> <?php the_content(); ?> </p> </div> </div>the ajax function
$(document).delegate('li.homus-partners-section-single', 'click', function(event) { event.preventDefault(); var pb_post_id = $(this).data('post-id'); var data = { 'action': 'GetPost', postURL : pb_post_id, }; $.post(ajaxURL, data, function(response) { $( '.homus-partners-detalis' ).html(response); }); });the php function
function GetPost(){ $cat = $_POST['catURL']; get_template_part($cat); exit(); } add_action('wp_ajax_nopriv_GetPost', 'GetPost');
EDIT 2
now my code look like this but i have no answer
markup of the clickable element
<li class="homus-partners-section-single" data-post-slug="<?php echo $post->post_name;?>"> <?php the_post_thumbnail(); ?>div where i want to display the item
<div class="homus-partners-detalis"> <?php get_template_part('single_pb_post_details'); ?> </div>php i'm calling in the div
<div class="homus-partners-detalis-img"> <?php the_post_thumbnail(); ?> </div> <div class="homus-partners-detalis-info"> <h4> <?php the_title(); ?> </h4> <p> <?php homus_excerpt('homus_pb_excerpt'); ?> </p> </div>ajax function
$(document).delegate('li.homus-partners-section-single', 'click', function(event) { event.preventDefault(); var pb_post_slug = $(this).data('post-slug'); var data = { 'action': 'GetPostDetails', postURL : "single_pb_post_details.php?slugid="+ pb_post_slug, }; $.post(ajaxURL, data, function(response) { $( '.homus-partners-detalis' ).html(response); alert('Got this from the server: ' + response); }); });the php function
function GetPostDetails(){ $details = $_POST['postURL']; get_template_part($details); exit(); } add_action('wp_ajax_nopriv_GetPostDetails', 'GetPostDetails');
GetPostwill only return, what? You need to put something to output there, so that there is something in theresponseof the ajax call....load("../single_pb_post_details.php?slugid=" + pb_post_slug);Is not a good way to load your.phpfile. Use wp_localize_script instead.function GetPostDetails(){ $details = $_POST['postURL']; get_template_part($details); exit(); } add_action('wp_ajax_nopriv_GetPost', 'GetPostDetails');but the only answere i have is a zerodie()orexit()in your output (the php function that you call in ajax).exit();but the answer is still zero