我正在努力将一些过滤器应用于WP\\u User\\u查询,我有以下查询,后面还显示了一些过滤器,当我应用这些过滤器时,它们出现在url结构中,那么/?性别=男性但我正在努力将过滤器连接到实际输出的内容,是否有一种简单的方法来获取我拥有的内容并将过滤器应用到阵列?谢谢
<?php
$args = array(
\'role\' => \'talent\',
\'order\' => \'DESC\',
\'orderby\' => \'user_registered\',
\'meta_key\' => \'position\',
\'number\' => \'15\',
\'meta_query\'=> array (
array(
\'key\' => \'picture\',
\'value\' => array(\'\'),
\'compare\' => \'NOT IN\'
),
array(
\'key\' => \'position\',
\'value\' => $title
)
)
);
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
if (!empty($authors))
{
foreach ($authors as $author)
{
?>
<?php include(locate_template(\'profile.php\')); ?>
<?php } ?>
<?php } else { ?>
<?php } ?>
过滤器
<form>
<strong>
Age
</strong>
<span>
<select name="age">
<?php
$orderby_options = array(
\'10\' => \'10\',
\'20\' => \'20\',
\'30\' => \'30\',
);
foreach( $orderby_options as $value => $label ) {
echo "<option ".selected( $_GET[\'age\'], $value )." value=\'$value\'>$label</option>";
}
?>
</select>
</span>
<strong>
Gender
</strong>
<span>
<select name="gender">
<?php
$orderby_options = array(
\'All\' => \'All\',
\'Male\' => \'Male\',
\'Female\' => \'Female\',
);
foreach( $orderby_options as $value => $label ) {
echo "<option ".selected( $_GET[\'gender\'], $value )." value=\'$value\'>$label</option>";
}
?>
</span>
<input type=\'submit\' value=\'Search\'>
</form>
SO网友:s_ha_dum
主要是一个PHP问题,但如果我理解你的问题,你会想要这样的问题:
$args = array(
\'role\' => \'talent\',
\'order\' => \'DESC\',
\'orderby\' => \'user_registered\',
\'meta_key\' => \'position\',
\'number\' => \'15\'
);
$meta = array (
array(
\'key\' => \'picture\',
\'value\' => array(\'\'),
\'compare\' => \'NOT IN\'
),
array(
\'key\' => \'position\',
\'value\' => $title
)
);
$orderby_options = array(
\'All\' => \'All\',
\'Male\' => \'Male\',
\'Female\' => \'Female\',
);
// var_dump($_GET);
if (!empty($_GET[\'gender\']) && in_array($_GET[\'gender\'],$orderby_options)) {
$meta[] = array(
\'key\' => \'gender\',
\'value\' => $orderby_options[$_GET[\'gender\']]
);
}