Created
December 7, 2012 18:52
-
-
Save gavinblair/4235484 to your computer and use it in GitHub Desktop.
wordpress 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
<?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