Skip to content

Commit

Permalink
Merge pull request #169 from humanmade/145-2-do-not-html-encode-json-…
Browse files Browse the repository at this point in the history
…response

Do not html encode json response
  • Loading branch information
joehoyle committed Mar 19, 2014
2 parents cf1f8d1 + 11d0aff commit 536e6e2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions classes.fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,12 @@ public function output_script() {
<?php if ( $this->args['multiple'] ) : ?>

<?php foreach ( (array) $this->value as $post_id ) : ?>
data.push( <?php echo sprintf( '{ id: %d, text: "%s" }', $post_id, get_the_title( $post_id ) ); ?> );
data.push( <?php echo json_encode( array( 'id' => $post_id, 'text' => html_entity_decode( get_the_title( $post_id ) ) ) ); ?> );
<?php endforeach; ?>

<?php else : ?>

data = <?php echo sprintf( '{ id: %d, text: "%s" }', $this->value, get_the_title( $this->value ) ); ?>;
data = <?php echo json_encode( array( 'id' => $post_id, 'text' => html_entity_decode( get_the_title( $post_id ) ) ) ); ?>;

<?php endif; ?>

Expand Down Expand Up @@ -1254,8 +1254,9 @@ function cmb_ajax_post_select() {

$json = array( 'total' => $query->found_posts, 'posts' => array() );

foreach ( $query->posts as $post_id )
array_push( $json['posts'], array( 'id' => $post_id, 'text' => get_the_title( $post_id ) ) );
foreach ( $query->posts as $post_id ) {
array_push( $json['posts'], array( 'id' => $post_id, 'text' => html_entity_decode( get_the_title( $post_id ) ) ) );
}

echo json_encode( $json );

Expand Down

0 comments on commit 536e6e2

Please sign in to comment.