Created
April 5, 2013 11:36
-
-
Save sagarjadhav/5318639 to your computer and use it in GitHub Desktop.
WordPress with ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Ajax Page Setup */ | |
$page = jQuery('.link a'); | |
$page.on('click', function (e) { | |
e.preventDefault(); | |
var pageID = jQuery(this).attr('data-id'); | |
var ajaxdata = { | |
action: 'load_pages', | |
page_id: pageID | |
}; | |
jQuery.post(dtb_ajaxurl, ajaxdata, function (res) { | |
console.log(res); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load Pages Ajax Function | |
*/ | |
function rtp_load_pages(){ | |
if( isset( $_POST['page_id'] ) ) { | |
$page_id = $_POST['page_id']; | |
$page = get_page( $page_id ); | |
$content = $page->post_content; | |
echo apply_filters('the_content', $content); | |
} | |
die(1); | |
} | |
add_action('wp_ajax_load_pages', 'rtp_load_pages'); | |
add_action('wp_ajax_nopriv_load_pages', 'rtp_load_pages'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var dtb_ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment