如何使下拉字段的关系使用或逻辑而不是php wordpress

发布于 2025-02-11 08:41:11 字数 1209 浏览 2 评论 0原文

嗨,我目前正在尝试编辑 city 下拉的关系,您可以在此页面在第一个字段 region 上使用或使用逻辑,

我试图更改和通过function.php文件,如下这无效,

function filter_florida_location() {

     ob_start();
        
        $tax_query = array('relation' => 'AND');
        if (isset($_POST['region']) && !empty($_POST['region']))
        {  
            $tax_query[] =  array(
                    'taxonomy' => 'region',
                    'field'    => 'term_id',
                    'terms'    =>  $_POST['region'],
                    //'operator' => 'IN',
                );
        } 
        
        
        if (isset($_POST['city']) && !empty($_POST['city']))
        {   
            foreach($_POST['city'] as $key => $val){
            $tax_query[] = array('relation' => 'OR');   
            $tax_query[][] =  array(
                    'taxonomy' => 'city',
                    'field'    => 'term_id',
                    'terms'    => array($val),
            );
            }   
        } 

谢谢你!

Hi I'm currently trying to edit the relation of the City dropdown which you can find on this page to use the the OR logic like on the first field Region

I have attempted to change the AND to OR through the function.php file like below but this didn't work

function filter_florida_location() {

     ob_start();
        
        $tax_query = array('relation' => 'AND');
        if (isset($_POST['region']) && !empty($_POST['region']))
        {  
            $tax_query[] =  array(
                    'taxonomy' => 'region',
                    'field'    => 'term_id',
                    'terms'    =>  $_POST['region'],
                    //'operator' => 'IN',
                );
        } 
        
        
        if (isset($_POST['city']) && !empty($_POST['city']))
        {   
            foreach($_POST['city'] as $key => $val){
            $tax_query[] = array('relation' => 'OR');   
            $tax_query[][] =  array(
                    'taxonomy' => 'city',
                    'field'    => 'term_id',
                    'terms'    => array($val),
            );
            }   
        } 

Thank you in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2025-02-18 08:41:11

您必须将其更改

$tax_query[] = array('relation' => 'OR');

$tax_query['relation'] = 'OR';

You have to change this

$tax_query[] = array('relation' => 'OR');

to

$tax_query['relation'] = 'OR';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文