2017-06-17 3 views
1

Variable von Seite zu Thema Funktion senden habe ich eine Funktion in der Thema Funktion Datei, die JSON-Daten zieht und erstellt eine Shortcode, die ich in einer Seite verwendenWordpress -

Meine Frage ist, wie die RID = Wert, um von eine Seite mit dem Shortcode [json_employees] und senden Sie die RID zurück zur Funktion?

function foobar2_func($atts){ 
ob_start(); 
$url = 'https://jdublu.com/api/wrsc/json_employee.php?RID=17965'; 
$data = file_get_contents($url); 
$items = str_replace('<p></p>', '', $items); 
$items = json_decode($data, true); 
?> 
add_shortcode('json_employees', 'foobar2_func'); 
+0

Haben Sie versucht, mit 'shortcode_atts'? – vel

Antwort

0

Ihre Short sollte

[json_employees RID='17965'] 

und Shortcode-Funktion ist

function foobar2_func($atts){ 
    ob_start(); 
    $atts = shortcode_atts(
    array(
     'RID' => 'id', 
    ), $atts); 

    $url = 'https://jdublu.com/api/wrsc/json_employee.php?RID='.esc_attr($atts['RID']); 
    $data = file_get_contents($url); 
    $items = str_replace('<p></p>', '', $items); 
    $items = json_decode($data, true); 
    return $items; 
} 
add_shortcode('json_employees', 'foobar2_func'); 
+0

danke, aber bekommt nicht die RID in der Funktion, was könnte sonst noch sein? – Mariano

+0

Diese Variable $ atts drucken und überprüfen – vel

+0

Ich habe und zeigt "Array" und nichts anderes – Mariano

0
function foobar2_func($atts){ 
     ob_start(); 
     $atts = shortcode_atts(
     array(
      'RID' => 'id', 
     ), $atts); 

     $url = 'https://jdublu.com/api/wrsc/json_employee.php?RID='.esc_attr($atts['RID']); 
     $data = file_get_contents($url); 
     $items = str_replace('<p></p>', '', $items); 
     $items = json_decode($data, true); 
     return $items; 
     print_r ($atts); 
    } 
    add_shortcode('json_employees', 'foobar2_func'); 

    and in the wordpress page 
    [json_employees RID='17965'] 

here is the page to test it http://bahiacr.com/test_json/ 
+0

Funktion foobar2_func ($ atts) { ob_start(); $ atts = shortcode_atts ( Array ( 'RID' => 'id', ), $ atts); $ url = 'https://jdublu.com/api/wrsc/json_employee.php?RID='.esc_attr ($atts['RID']); $ data = file_get_contents ($ url); $ items = str_replace ('

', '', $ items); $ items = json_decode ($ data, true); return $ items; print_r ($ atts); } add_shortcode ('json_mitarbeiter', 'foobar2_func'); und in der Wordpress-Seite [Json_Mitarbeiter RID = '17965'] http://bahiacr.com/test_json/ – Mariano