Skip to content

Instantly share code, notes, and snippets.

@jonathanbossenger
Created August 27, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanbossenger/dd5e6f15a5f8a954ead700052e401949 to your computer and use it in GitHub Desktop.
Save jonathanbossenger/dd5e6f15a5f8a954ead700052e401949 to your computer and use it in GitHub Desktop.
JSON Output
function ssa_get_safe_podcast_json() {
$args = array(
'post_type' => 'podcast',
'posts_per_page' => - 1,
'post_status' => 'any',
'orderby' => 'ID',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'audio_file',
'compare' => 'EXISTS',
),
array(
'key' => 'audio_file',
'value' => '',
'compare' => '!=',
)
),
);
$podcast_query = new WP_Query( $args );
$podcasts = $podcast_query->get_posts();
$podcast_data = array();
foreach ( $podcasts as $podcast ) {
$podcast_data[ $podcast->ID ] = array(
'post_id' => $podcast->ID,
'post_title' => $podcast->post_title,
'post_content' => '',
'post_date' => $podcast->post_date,
'audio_file' => get_post_meta( $podcast->ID, 'audio_file', true ),
);
}
echo '<textarea cols="200" rows="25">';
print_r( wp_json_encode( $podcast_data ) );
echo '</textarea>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment