Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress中的Json或xml解析_Xml_Json_Wordpress - Fatal编程技术网

wordpress中的Json或xml解析

wordpress中的Json或xml解析,xml,json,wordpress,Xml,Json,Wordpress,我有一个使用自定义字段的主题。我想做这样的事 tt0068646 我的自定义字段代码 <span> <?php echo get_post_meta($post->ID, 'rate', true); ?> </span> 我想从www.omdbapi.com获得imdb评级。如何执行此操作?此小函数将检索电影ID请求的结果,即http://www.omdbapi.com/?i=VALID-电影ID。结果在var$body中: function ge

我有一个使用自定义字段的主题。我想做这样的事

tt0068646
我的自定义字段代码

<span> <?php echo get_post_meta($post->ID, 'rate', true); ?> </span>

我想从www.omdbapi.com获得imdb评级。如何执行此操作?

此小函数将检索电影ID请求的结果,即
http://www.omdbapi.com/?i=VALID-电影ID
。结果在var
$body
中:

function get_imdb_json( $id )
{
    $url = "http://www.omdbapi.com/?i=$id";
    $response = wp_remote_get( $url );

    // Parse the request
    if ( ! is_wp_error( $response ) )//&& !isset($response['body']['error'] ) ) 
    {
        $body = json_decode( wp_remote_retrieve_body( $response ), true );
        return '<pre>' . print_r( $body, true ) . '</pre>';
    }
    return false;
}
在你的情况下,这将是一个问题:

if( !is_admin() )
{
    add_filter( 'the_content', function( $content ){
        if( isset( $_GET['imdb'] ) && !empty( $_GET['imdb'] ) )
        {
            if( $ok = get_imdb_json( $_GET['imdb'] ) )
                return $ok;
        }    
        return $content;
    });
}
echo get_imdb_json( get_post_meta($post->ID, 'rate', true) );