Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created December 7, 2012 18:52
Show Gist options
  • Save gavinblair/4235484 to your computer and use it in GitHub Desktop.
Save gavinblair/4235484 to your computer and use it in GitHub Desktop.
wordpress ajax
<?php
// wp-admin/admin-ajax.php?action=getspeaker&a=b&c=d...
add_action( 'wp_ajax_nopriv_getspeaker', 'getspeaker' );
add_action( 'wp_ajax_getspeaker', 'getspeaker' );
function getspeaker(){
$offset = $_REQUEST['offset'];
$already = explode(",",$_REQUEST['already']);
$retID = -1;
do {
$query = new WP_Query( 'post_type=speaker&category_name=featured&posts_per_page=1&orderby=modified&offset='.$offset );
$result = null;
while ( $query->have_posts() ) {
$query->the_post();
$result->link = get_permalink();
$image = array_shift(get_children('post_type=attachment&post_mime_type=image&post_parent='.get_the_ID() ));
$result->source = $image->guid;
$custom = get_post_custom();
$result->title = get_the_title();
$result->description = $custom['title'][0];
$result->id = $retID = get_the_ID();
}
$offset++;
} while(in_array($retID, $already));
echo json_encode($result);
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment