dongleiwei2182 2013-01-15 17:26
浏览 17

使用#content中的ajax.load检索wordpress循环外的查询

I am working on an advanced search on wordpress based on custom taxonomies. I'm stuck since 48h so I was hoping to have some help or thought...

Step 1 --- in the js file the query strings are created like that:

if (jQuery('#s').val() == ''){
URL = "/?genre=" + genre + '...other Stuff' #content';
}else{
URL = "/?s="+searchQueryString+"&genre=" + genre +'...other stuff' #content';
}

It nicelly load my custom loop in my #content div without changing the browser url or reloading the header, which is pretty good...so far. :-)

Step 2 --- then I wrote 2 functions in my function.php , one to load the loop with the GET[] elements on main page, using new WP_Query and one that does the same thing for search queries:

add_action('pre_get_posts','SearchFilter');

Which is compiling my GET[] filters with the GET[s] in the content.php, Still all good....

Step 3 --- (problem^^)---

I want to add a css class to desactivate the radio buttons located in my header.php, depending on the results in the loop.

Try-1 I thought I could create a php array to compile the terms found while the loop is happening, and then compare it with my buttons value.like that:

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'slugs');
$results = wp_get_post_terms(get_the_ID(),'category',$args);  
foreach ($results as $result){
    array_push($stack, $result);

}

But there is no way to retrieve the data from that array in the header afterwhile, or to create it from the header using things like global $post;since my url doesn't change. it just shows the homepage query.

Try-2 I also thought I could encode it to json and then put some action in my js file. but so far it just return json unexpected character, and I got the feeling that even if I crack it, its not going to be the right way since its going to make the js file heavier.

May be I'm just missing something about the Global wp_query and I don't need to charge my script?

Excuse my english and the long question,

thanks a lot in advance if you have an idea,

DACO

  • 写回答

1条回答 默认 最新

  • dti3914 2013-01-17 07:04
    关注

    I'm going to use wp_localize_script to export the array to my js script, Thanks sorted

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?