亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

下拉過濾器無法正常工作

下拉過濾器無法正常工作

PHP
蕭十郎 2023-06-24 15:07:39
我的代碼:<?php    function filter_profiles_by_country()    {        $url = get_site_url();        if ( $terms = get_terms( array('taxonomy' => 'country','orderby' => 'name') ) )        {            // if categories exist, display the dropdown            echo '<select name="categoryfilter" onchange="if (this.value) window.location.href=this.value">';            echo '    <option value="'.$url.'/profiles">All Profiles...</option>';            foreach ( $terms as $term )            {                // ID of the category as an option value                echo '    <option value="'.$url ."/country/". $term->name . '">' . $term->name . '</option>';             }            echo '</select>';        }    }?>當我單擊“所有配置文件”時,它應該將我帶到 /profiles/ 頁面。但它不起作用。
查看完整描述

1 回答

?
慕絲7291255

TA貢獻1859條經驗 獲得超6個贊

  <?php 


function filter_profiles_by_country(){

        $url = get_site_url();

        global $wp;

    $current_url = home_url(add_query_arg(array(), $wp->request));

    

    if( $terms = get_terms( array(

        'taxonomy' => 'country',

        'orderby' => 'name'

    ) ) ) : 

        // if categories exist, display the dropdown

        echo '<select name="categoryfilter" onchange="if (this.value) window.location.href=this.value"><option value="'.$url.'/profiles/">All Profiles...</option>';

        foreach ( $terms as $term ) :

            $loadedItem = $url."/country/".$term->name;

            $selectedItem = ($current_url == $loadedItem)? "selected": "";

            echo '<option '.$selectedItem.' value="'.$url ."/country/". $term->name . '">' . $term->name . '</option>'; // ID of the category as an option value

        endforeach;

        echo '</select>';

    endif;

    }

?>

嘗試這個。


查看完整回答
反對 回復 2023-06-24
  • 1 回答
  • 0 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號