Skip to content

Instantly share code, notes, and snippets.

@generatepress
Created July 27, 2014 20:04
Show Gist options
  • Save generatepress/a04ababa46653c9b027c to your computer and use it in GitHub Desktop.
Save generatepress/a04ababa46653c9b027c to your computer and use it in GitHub Desktop.
<?php
require_once( '../../wp-load.php' );
if ( $_POST['generate_action'] == 'get_email' ) :
$args = array(
'post_type' => 'edd_license',
'showposts' => -1,
's' => $_POST['email']
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
$posts = $the_query->get_posts();
$names = array();
$licenses = array();
foreach ( $posts as $post ) {
$license = get_post_meta( $post->ID, '_edd_sl_key', true );
$item_name = $post->post_title;
$items[] = substr( $item_name, 0, strrpos($item_name,' -') );
}
echo json_encode($items);
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
elseif ( $_POST['generate_action'] == 'get_license' ) :
$args = array(
'post_type' => 'edd_license',
'showposts' => -1,
's' => $_POST['email'] . ' ' . $_POST['download']
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
$posts = $the_query->get_posts();
$names = array();
$licenses = array();
foreach ( $posts as $post ) {
$license = get_post_meta( $post->ID, '_edd_sl_key', true );
$licenses[] = $license;
}
echo json_encode($licenses);
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment