wordpress json_decode is not working, I am trying to get value form wp_option table

青春壹個敷衍的年華 提交于 2019-12-26 06:04:15

问题


When I am trying to decode JSON with this code the output is

ArrayArray ( [0] => )

I do not know why WordPress doesn't support this

 <?php
    global $wpdb;
    $mylink = $wpdb->get_results( "SELECT option_value FROM wp_options WHERE option_id=62167", ARRAY_N );
    $raw = stripslashes_deep($mylink);
            $data = array();
            foreach ($raw as $json) {
                        echo $json;

                $item = @json_decode($json, true);

                $data[] = $item;

                            print_r($data);

            }
    ?>

回答1:


Hello you need to unserealize the data first when your query get data from database, That is serealized data and when we get it from db we need to unserealize it.

 global $wpdb;
    $mylink = $wpdb->get_results("SELECT option_value FROM wp_options WHERE option_id=1223",ARRAY_A);

   $raw = stripslashes_deep($mylink);
  $data = $raw[0]['option_value'];
  $datas = unserialize($data);
  foreach ($datas as $key => $value) {
    print_r($value);
  }


来源:https://stackoverflow.com/questions/35687733/wordpress-json-decode-is-not-working-i-am-trying-to-get-value-form-wp-option-ta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!