2017-05-09 11 views
0

エコー用とリモートワードプレスで応答で同じURLではありませんは、なぜ私はこの小さなショートを持って

function starlight_count() { 
$url = 'https://herokuapp.com/creditcount?contact_id=' . do_shortcode('[i4w_db__FirebaseID]'); 
$response = wp_remote_get(esc_url_raw($url)); 
$api_response = json_decode(wp_remote_retrieve_body($response), true); 
$response_message = wp_remote_retrieve_response_message($response); 

ob_start(); ?> 
<?php 
    echo $url; 
echo $response_message; 
    print_r($response); ?> 
<?php 
    return ob_get_clean(); 

} 
add_shortcode('starlight-count', 'starlight_count'); 

最初のエコーが

https://herokuapp.com/creditcount?contact_id=-KhwKGq4EYNf0GCiw8Kn 

を返しますが、実際の呼び出しが返されます500エラー、およびそれがマージされたデータのURLを使用していないのはなぜ

[url] => https://herokuapp.com/creditcount?contact_id=%5Bi4w_db__FirebaseID%5D 

からデータを要求しようとしていますか?

答えて

0

ショートコードの中でショートコードを呼び出しているためです。あなたは、次のようなロジックを実行する必要があり

function starlight_count($atts) { 
$params = shortcode_atts(array(
     'pass' => '0', 
    ), $atts); 

$url = 'https://herokuapp.com/creditcount?contact_id='.$params['pass']; 
$response = wp_remote_get(esc_url_raw($url)); 
$api_response = json_decode(wp_remote_retrieve_body($response), true); 
$response_message = wp_remote_retrieve_response_message($response); 

ob_start(); ?> 
<?php 
    echo $url; 
//echo $response_message; 
    // print_r($response); ?> 
<?php 
    return ob_get_clean(); 

} 
add_shortcode('starlight-count', 'starlight_count'); 
$variable = do_shortcode('[i4w_db__FirebaseID]'); 
echo do_shortcode('[starlight-count pass='.$variable.']'); 
関連する問題