B
B
BonBon Slick2016-07-19 13:00:06
PHP
BonBon Slick, 2016-07-19 13:00:06

Why does json decode return NULL?

$demoids = json_encode(['111','222','333' ],JSON_UNESCAPED_UNICODE);
    update_post_meta(get_the_id(), 'media_shortcode_', $demoids);

    $demotext = [
    'title' => ' Some testing text lorem ipsum ... ',
    ];
    update_post_meta(get_the_id(), 'media_shortcode_111', $demotext);

    $get_box_data = get_post_meta( get_the_id(), 'demoids ', true );
 //тут уже NULL  $get_box_data, но мне надо что бы сюда выводило поле title шорткодов, которые исопльзую // дальше в цикле
    $meta_box_ids = json_decode($get_box_data);

    foreach ($meta_box_ids as $key => $value) {
      if( $box_data = get_post_meta( get_the_id(), 'media_shortcode_'.$value, true ) ){
        ?>
        <input type='text' id='' name='id[""]' size='46'  value='<?php echo $box_data["title"];?>' />
        <?php
      }
    }

There is already a NULL value, $get_box_datawhat am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
saltydogd, 2016-07-19
@BonBonSlick

I would venture to suggest that get_post_meta does not find data by the key - 'demoids' , because there are keys 'media_shortcode_' and 'media_shortcode_111'

A
Andrey, 2016-07-19
@Andrey052

NULL - undefined value (the variable is not assigned any value).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question