Takes of the function's arguments about how their own
Categories: memorandum function
2010-04-14 Last update:
2009-01-12: Sun Posts
The argument received or if you want to create custom functions, as query_posts,
query_posts ('cat = 5 & order = DESC') If you want to format is a way of like.
use of wp_parse_args
(array argument, the default) wp_parse_args Go to an associative array 'key = value' to split it on '&' arguments when you use it.
For those with no value will use the initial value.
Specifically used as follows.
function myfunction( $args='' ) {
// 初期値の設定
$defaults = array('key1' => 10, 'key2' => 0, 'order' => 'DESC', 'key3' => 'value');
// 引数を取得
$args = wp_parse_args($args, $defaults);
if($args['key2'] > 0) {
// 処理
}
}
関数を使う場合は以下のようになります。
// 関数呼び出し
myfunction('key2=10&key3=test');
これで後々に引数を追加しても順番を気にする必要が無いので拡張し易くなります。
- タグ
- function , WordPress備忘録 , wp_parse_args , 引数 , 関数
- トラックバックURL




























