dqxsuig64994 2012-05-27 14:05 采纳率: 0%
浏览 59

通过元数据进行Wordpress搜索

Here's what I'm trying to achieve:

I have a custom search form to search for posts based on various metadata.

This code contains the settings for the WordPress search: http://pastebin.com/5dj16Atj The references to the custom fields are all in there.

This code is referenced in the file above and contains the actual layout for the custom search form: http://pastie.org/private/yebozm9kaqazywkilr8fkq

My main problem is that only 3 fields work in the custom search form, namely; Price Range and Area. The remaining fields such as Property Type (srch_ptype), age (srch_age) and City just don't show up as criteria in the search. I would like all the fields to be functional and get included as criteria when people are searching. Kindly take a look at both files to see what I have gotten wrong.

Thanks a lot.

Edit: adomnom was kind enough to suggest that i use wp_query for the search. I would appreciate if anyone can tell me how to connect the search form with the query.

  • 写回答

1条回答 默认 最新

  • drutcs7210 2012-06-03 04:51
    关注

    I'm with markratledge on this one. I'd recommend looking into get_posts() or query_posts(), or even overriding the default wordpress search with special hooks.

    You should be able to do something like...


    Define the parameters of the search (more at WP_Query Page) and run it

    $searchArgs = array(
        'post_type' => 'post',
        'meta_query' = array(
            'relation' => 'AND',
            array( 'key' => 'srch_age',   'value' => $_REQUEST['srch_age'] ),
            array( 'key' => 'srch_ptype', 'value' => $_REQUEST['srch_ptype'] )
            // ... Add as many other criteria as you need
        )
    );
    
    query_posts( $searchArgs );
    while( have_posts() ): the_post();
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数