1
我試圖通過用3個用戶元值進行過濾來創建用戶列表。通過使用Wordpress中的查詢使用兩個自定義元字段列出用戶
首先,我創建了一個具有兩個選擇選項的表單,這兩個選項對於元字段具有不同的可能值。然後,我創建了一個過濾的查詢並使用表單中的值,第一個值($search
)完美地工作,但第二個不起作用,我不知道爲什麼。
如果我在
'key' => 'distrito_profissao'
替代第二個值將很好地工作。
'value' => 'Leiria'
我也弄不明白,爲什麼這個值($search2
)當我提交它,另一個則沒有保持保存。
add_shortcode('user_search_C','My_User_search_C');
function My_User_search_C() {
?>
<?php
$search=get_query_var('as');
$search2=get_query_var('bs');
// Array of stdClass objects.
?>
<ul class="users_list">
<form>
<label for="as" ></label>
<select name="as" id="as" >
<option value="" <?php selected($search, ""); ?> ></option>
<option value="CAPDA"<?php selected($search, "CAPDA"); ?> >Crianças e adolescentes com perturbações do desenvolvimento e aprendizagem</option>
<option value="CMPIP"<?php selected($search, "CMPIP"); ?> >Crianças em meio pré-escolar e/ou Intervenção Precoce</option>
<option value="CACP"<?php selected($search, "CACP"); ?> >Crianças e adolescentes em contexto pedopsiquiátrico</option>
<option value="MA" <?php selected($search, "MA"); ?> >Meio Aquático</option>
<option value="SMAI"<?php selected($search, "SMAI"); ?> >Saúde mental do adulto e do idoso</option>
</select><br/>
<label for="bs"></label>
<select name="bs" id="bs" >
<option value="" <?php selected($search2, ""); ?>></option>
<option value="Beja" <?php selected($search2, "Beja"); ?> >Beja</option>
<option value="Braga" <?php selected($search2, "Braga"); ?> >Braga</option>
<option value="Bragança" <?php selected($search2, "Bragança"); ?> >Bragança</option>
<option value="Castelo Branco" <?php selected($search2, "Castelo Branco"); ?> >Castelo Branco</option>
<option value="Coimbra" <?php selected($search2, "Coimbra"); ?> >Coimbra</option>
<option value="Évora" <?php selected($search2, "Évora"); ?> >Évora</option>
<option value="Guarda" <?php selected($search2, "Guarda"); ?> >Guarda</option>
<option value="Leiria" <?php selected($search2, "Leiria"); ?> >Leiria</option>
<option value="Lisboa" <?php selected($search2, "Lisboa"); ?> >Lisboa</option>
<option value="Portalegre" <?php selected($search2, "Portalegre"); ?> >Portalegre</option>
<option value="Porto" <?php selected($search2, "Porto"); ?> >Porto</option>
<option value="Santarém" <?php selected($search2, "Santarém"); ?> >Santarém</option>
<option value="Setúbal" <?php selected($search2, "Setúbal"); ?> >Setúbal</option>
<option value="Viana do Castelo" <?php selected($search2, "Viana do Castelo"); ?> >Viana do Castelo</option>
<option value="Vila Real" <?php selected($search2, "Vila Real"); ?> >Vila Real</option>
<option value="Viseu" <?php selected($search2, "Viseu"); ?> >Viseu</option>
</select></br>
<input type="submit" id="submit" />
</form>
<?php
$blogusers = get_users(array('fields' => array('display_name'),array('meta_key' => $metakey,$metakey2),array('meta_value' => $search2,$search),'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'list_prof',
'value' => 'S',
'compare' => '='
),
array('relation' => 'OR',
array(
'key' => 'distrito_profissao',
'value' => $search2,
'compare' => '='
),
array(
'key' => 'area_profissao',
'value' => $search,
'compare' => '='
)
))));
foreach ($blogusers as $user) {
echo '<li>' . esc_html($user->display_name) . '</li>';
}
?>
</ul>
<?php
}
我剛剛做了,但結果是一樣的,它仍然不保存第二個變量 –
您是否嘗試回顯兩個變量以確保$ search2爲空? – Stevish
這正是$ serch2總是空的地方,我不知道爲什麼,因爲代碼和$ search完全一樣!並且$ search給出了適當的回聲。 –