dongquan8753 2012-08-11 10:47
浏览 67

在Wordpress中设置数组

I am currently trying to set up a search in Wordpress, though am having issues because I am currently losing the search term in the query. I believe this is because I am running a new query instead of setting the WP query.

Current problem

Currently I am running the following command (an example where I wish to search taxonomies feature and location and the search term.

if ($s_feature != "" && $s_location != "")
    {
        $s_feat_array = array(
            'taxonomy' => 'feature',
            'terms' => array($s_feature),
            'field' => 'slug',
            'relation' => 'AND',
            );
        $s_loc_array = array(
            'taxonomy' => 'location',
            'terms' => array($s_location),
            'field' => 'slug',
            );
        $housequery['tax_query'] = array(
            'relation' => 'AND',
            'orderby' => 'title',
            'order' => 'ASC',
            $s_feat_array,
            $s_loc_array
        );
        query_posts($housequery);
    }

Unfortunately, this is not searching the submitted search term nor any other queries.

My attempt

I therefore think that it should be 'set' to $query rather than running a new command. I have seen that the following code DOES work:

$query->set('post_type',array('houses'));

However, I have tried to modify the query as follows and instead I get a fatal error (Call to member function on a non-object):

$query->set(array('taxonomy','location','terms',
array($s_location),'field',array('slug')));

I think it's to do with the array not being structured correctly though am really quite puzzled, so any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dqftyn1717 2012-08-11 18:12
    关注

    $housequery['tax_query'] is an item in an array at index tax_query. You then make that an array. But when you call query_posts, you do not reference $housequery['tax_query'].

    Try query_posts($housequery['tax_query']); or remove tax_query completely if you can.

    $housequery = array(
                'relation' => 'AND',
                'orderby' => 'title',
                'order' => 'ASC',
                $s_feat_array,
                $s_loc_array
            );
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作