2
私はこのコードを使用して、クエリー文字列が存在するかどうかをチェックし、値に基づいて内容をエコーします。URLにクエリーストリングが表示されていないことを確認
コードがあれば働いている:
www.mywebsite.com/?position=&category=&country=
www.mywebsite.com/?position=position1&category=&country=
www.mywebsite.com/?position=&category=category1&country=
www.mywebsite.com/?position=&category=&country=country1
www.mywebsite.com/?position=&category=category1&country=country
.
.
and so forth.
が、URLは、他のブロックが実行されていない親のクエリ文字列せずにただwww.mywebsite.comある場合。
私の現在のコードは次のとおりです。
<?php
// args
if ($_GET){
if ($_GET['category'] && $_GET['country']) {
$args = array(
'numberposts' => -1,
'post_type' => 'job_order',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'j_category',
'value' => $_GET['category'],
'compare' => '='
),
array(
'key' => 'j_country',
'value' => $_GET['country'],
'compare' => '='
)
)
);
} elseif ($_GET['category']) {
$args = array(
'numberposts' => -1,
'post_type' => 'job_order',
'meta_key' => 'j_category',
'meta_value' => $_GET['category']
);
} elseif ($_GET['country']) {
$args = array(
'numberposts' => -1,
'post_type' => 'job_order',
'meta_key' => 'j_country',
'meta_value' => $_GET['country']
);
} else {
$args = array(
'numberposts' => -1,
'post_type' => 'job_order'
);
}
} else{
$args = array(
'numberposts' => -1,
'post_type' => 'job_order'
);
}
// query
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts()) : $the_query->the_post();
?>
あなたはあなたのコードの中でポジションを探しているわけではないので、質問には関係ありません。 –