2015-12-19 99 views
0

我試圖傳遞函數參數,並打印在WordPress插件輸出我沒能在這裏傳遞的參數是我的代碼如何通過參數的WordPress插件

global $postidd; 
$postidd=$_REQUEST["postid"]; 
function getcontent($postidd) 
{ 
    // do something with the args 


if($postidd) 
{ 

     $args12 = array(
        'p'=>15, 
        'post_type' => 'offers', 
        'orderby' => 'title', 
        'order' => 'ASC' 
       ); 
     $the_query12 = new WP_Query($args12);   
     if ($the_query12->have_posts()) : while ($the_query12->have_posts()) : $the_query12->the_post(); 

    return $postidd; 

     endwhile;endif;  

     return $postidd; 

} 
} 
+0

您需要解釋更多的問題。你在哪裏調用這個函數? –

回答

0

如果你想你的函數之外的任何變量可用於您的功能,然後通過使用'使用'關鍵字像這樣使用閉包:

$postidd=$_REQUEST["postid"]; 
function getcontent($somevariable) use ($postidd) { 
.... 

or 
declare it global inside the function like this: 
function getcontent($somevariable) { 
global $postidd 


but using global is considered a bad practice