As by means of ajax to load the parameter of get_template_part in wordpress?

0 like 0 dislike
4 views
I must say that is not strong in this question, but now I have an answer from wordpress occurs in the file functions.php and I would like the template output to make a separate file, but do not understand how to do it.

Now the code looks like this:
js
jQuery(function($) { $('body').on('click', '.portfolio-item-link', function() { var id_post = $(this).attr('rel'), ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; $.ajax({ type: 'POST', url: ajaxurl, data: { 'post_id': id_post, 'action': 'f711_get_post_content' }, success: function(result) { alert('done'); } }); }); });


php function.php:
add_action( 'wp_ajax_f711_get_post_content', 'f711_get_post_content_callback' ); add_action( 'wp_ajax_nopriv_f711_get_post_content', 'f711_get_post_content_callback' ); f711_get_post_content_callback function() { // retrieve the post_id, and sanitize it to enhance security $post_id = intval($_POST['post_id'] ); // get the post $thispost = get_post( $post_id, ARRAY_A ); $post_thumb = get_the_post_thumbnail($post_id); $post_title = get_the_title($post_id); $post_content = apply_filters( 'the_content', get_the_content() ); echo' '. $post_title . ''. apply_filters('the_content', get_post_field('post_content', $post_id)) . ' '; }
by | 4 views

1 Answer

0 like 0 dislike
Try the function hm_get_tempalte_partfrom here
by

Related questions

0 like 0 dislike
5 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
33,911 users