2016-06-21 15 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; 

これが返されます:文字列:468 |文字列:468 |ブール:

場合、私のようなので、2行目に$たTestStringの値でハードコード:

$testString = '468';

結果は次のとおりです。文字列:468 |文字列:468 |文字列:56

最後の変数は、私が必要とするものを返すようになりました。

私の疑惑は、変数$ this_post_idがショートコードのオブジェクトを参照しているという疑いがありますが、私はこれを回避しようとすることに成功していません。

+0

内容、型、(後者を使用して)変数の参照を見るには 'var_dump($ variable)'または 'debug_zval_dump($ variable)'を使います。 – Sven

答えて

0

do_shortcode関数の機能の詳細については、公式ドキュメント(https://developer.wordpress.org/reference/functions/do_shortcode/)を読んで、あなたの状況で何が返ってきたのかを理解しておくとよいでしょうか?

あなたのケースではdo_shortcodeが正しく動作しません - '[cred_post_parent GET = "ID"]' のparamとして、あなたがそれに渡されたことを完全な文字列をreturnd、そう

$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"]'); 

この機能と必要なパラメータを知りたいのですが、彼女の仕事を手伝ってください。

役立ちますか?

関連する問題