私がやろうとしているのは、検索フォームのメタ キーを使用して WordPress カスタム投稿タイプをクエリすることです。検索フォームはユーザー入力を受け取り、一致基準に基づいて結果を表示します。フォームのフィールドの一部は空白になる可能性があるため、クエリ引数に空白の値を渡さないようにする必要があります。引数配列内で if を使用する必要があります。
どんな種類の助けにも感謝します。
これは私が使用しているコードですが、エラーメッセージが表示されます。
Parse error: syntax error, unexpected T_IF, expecting ')'
これが私のコードです:
if (isset($POST['stock']) && !empty($POST['stock'])) {
$stock = $POST['stock'];
}
if (isset($POST['mineral']) && !empty($POST['mineral'])) {
$mineral = $POST['mineral'];
}
if (isset($POST['species']) && !empty($POST['species'])) {
$species = $POST['species'];
}
if (isset($POST['color']) && !empty($POST['color'])) {
$color = $POST['color'];
}
if (isset($POST['chemicalclass']) && !empty($POST['chemicalclass'])) {
$chemicalclass = $POST['chemicalclass'];
}
if (isset($POST['locality']) && !empty($POST['locality'])) {
$locality = $POST['locality'];
}
if (isset($POST['description']) && !empty($POST['description'])) {
$description = $POST['description'];
}
if (isset($POST['size']) && !empty($POST['size'])) {
$size = $POST['size'];
}
if (isset($POST['pricegt'])) {
$pricegt = $POST['pricegt'];
} else {
$pricegt = 0;
}
if (isset($POST['pricelt'])) {
$pricelt = $POST['pricelt'];
} else {
$pricelt = 999999;
}
$args = array(
'post_type' => 'products',
'productspecies' => $species,
'localities' => $locality,
'meta_query' => array(
//'relation' => 'OR',
array(
'key' => '_price',
'value' => array( $pricegt, $pricelt ),
'compare' => 'BETWEEN',
'type' => 'numeric',
),
if ($mineral) {
array(
'key' => '_components',
'value' => $mineral,
),
}
if ($stock) {
array(
'key' => '_lotnum',
'value' => $stock,
),
}
if ($color) {
array(
'key' => '_color',
'value' => $color,
),
}
if ($description) {
array(
'key' => '_smalldesc',
'value' => $description,
'compare' => 'LIKE',
),
}
if ($size) {
array(
'key' => '_size',
'value' => $size,
),
}
if ($chemicalclass) {
array(
'key' => '_chemicalclass',
'valeu' => $chemicalclass,
),
}
),
);
?>
<?php $query = new WP_Query( $args ); ?>
<div class="postcount">We Found A Total Of <span><?php echo $query->post_count;?></span> Items Maching Your Search</div>
<?php if ( $query->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
私が間違っていることは何ですか?