【PHP】配列に追加(結合)する|array_merge
記事更新日:2022-09-10

array_merge
ひとつまたは複数の配列をマージする
WordPressでの使い方サンプル

引数で配列を渡すとき、条件ごとに配列の中身を変更する
if (is_archive()) {
$args = array(
'post_status' => 'publish',
"posts_per_page" => -1,
"orderby" => "rand",
"post__not_in" => "", //現在のページを除外する場合:しない場合は空にする
);
if (is_post_type_archive('post')) {
$args = array_merge($args, array(
'post_type' => 'post',
));
} elseif (is_post_type_archive('xxx')) {
$args = array_merge($args, array(
'post_type' => 'xxx',
));
};
echo 関数名($args);
2022-09-10
編集後記:
この記事の内容がベストではないかもしれません。