使用以下方法进行操作。也许有更好的方法可以做到这一点,但这就足够了。
Added IF
statement for options
if($_POST[\'date\'] === \'HIGH\'){
$order = \'meta_value_num\';
$sort = \'DESC\';
}
elseif ($_POST[\'date\'] === \'LOW\'){
$order = \'meta_value_num\';
$sort = \'ASC\';
}
elseif ($_POST[\'date\'] === \'ASC\'){
$order = \'date\';
$sort = \'ASC\';
}
elseif ($_POST[\'date\'] === \'DESC\'){
$order = \'date\';
$sort = \'DESC\';
}
Then inside the $args
$args = array(
\'order\' => $sort,
\'post_type\' => \'product\',
\'meta_key\' => \'ek-product-price\',
\'orderby\' => $order,
)
Form
<select id="select1" type="text" name="date">
<option value="ASC" type="hidden">ASC</option>
<option value="DESC" type="hidden">DESC</option>
<option value="HIGH" type="hidden">HIGH</option>
<option value="LOW" type="hidden">LOW</option>
</select>