2016-06-21 37 views
0

我有一個簡單的WordPress短代碼,得到了意想不到的結果。這是不起作用的:我認爲這個變量是引用?

$this_post_id = do_shortcode('[cred_post_parent get="id"]'); 
$testString = $this_post_id; 
$parent_id = wpcf_pr_post_get_belongs($testString, 'wa-listing'); 
$variableType1 = gettype($testString); 
$variableType2 = gettype($this_post_id); 
$variableType3 = gettype($parent_id); 
return $variableType1.': '.$testString.' | '.$variableType2.': '.$this_post_id.' | '.$variableType3.': '.$parent_id; 

返回:string:468 |字符串:468 |布爾:

如果我硬編碼爲$的TestString值在第二行,像這樣:

$testString = '468';

結果是:字符串:468 |字符串:468 |字符串:56

最後一個變量現在返回我所需要的。

我懷疑變量$ this_post_id是引用短代碼中的對象,但我沒有成功嘗試解決這個問題。

+0

使用'var_dump($ variable)'或'debug_zval_dump($ variable)'來查看內容,類型和(使用後者)變量的refcount。 – Sven

回答

0

也許從官方文檔 - https://developer.wordpress.org/reference/functions/do_shortcode/中瞭解關於do_shortcode函數功能的更多信息,瞭解它在什麼情況下的返回值和熱點?

在你的情況do_shortcode不能正常工作 - returnd,你傳遞給它PARAM '[cred_post_parent GET = 「ID」]' 滿弦,所以

$parent_id = wpcf_pr_post_get_belongs($testString, 'wa-listing'); 

返回false和

$variableType3 = gettype($parent_id); 

返回布爾值 所以代碼完美的工作,在邏輯上的問題。在你如何打電話的問題

$this_post_id = do_shortcode('[cred_post_parent get="id"]'); 

嘗試閱讀更多關於此功能和他們需要什麼params讓她完成工作。

它有幫助嗎?

相關問題