为了账号安全,请及时绑定邮箱和手机立即绑定

下拉过滤器无法正常工作

下拉过滤器无法正常工作

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 关注
  • 119 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号