Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Advanced search form with filters for custom taxonomies and custom fields

I think something like this you would be best writing yourself.

Take a look at: http://www.catalysthomes.co.uk/homes-for-sale/

Properties are loaded into a CPT and I have my own custom search in the sidebar. Of that search its searching a number of things such as taxonomies, custom fields and ordering by date price etc.

So how do I achieve this? I submit the form to a page template and from there I deal with the post data and build a new WP_query based on the search criteria. I use sessions to store the search variables so that I can paginate the results.

WP_Query is very powerful. Take a look: http://codex.wordpress.org/Class_Reference/WP_Query

In there you can use meta_query to query multiple custom fields and use tax_query to query your taxonomies, plus there is more. Below is how mine is built to give you an idea.

Template File:

  <?php
  $temp = $wp_query;
  $wp_query = NULL;
  $args = array();
  ?>

  <?php include("functions/Homes-for-sale/propertyrawresults.php"); ?>
  <?php include("functions/Homes-for-sale/propertysearchresults.php"); ?>

  <?php
  $args['post_type'] = "homes-for-sale";
  $args['showposts'] = 10;
  $args['paged'] = $paged;
  $wp_query = new WP_Query($args);
  ?>

  <?php include("functions/Homes-for-sale/propertylistlayout.php"); ?>

Raw Results

<?php
if($_POST['sortby']) {
    $_SESSION['prop_selectedsortby'] = $_POST['sortby'];
}

switch($_SESSION['prop_selectedsortby']) {
    case "name-asc": $args['order'] = "ASC"; $args['orderby'] = "title"; break;
    case "name-desc": $args['orderby'] = "title"; break;
    case "price-asc": $args['order'] = "ASC"; $args['orderby'] = "meta_value_num"; $args['meta_key'] = "chb_homes_for_sale_specifics_fmv"; break;
    case "price-desc": $args['orderby'] = "meta_value_num"; $args['meta_key'] = "chb_homes_for_sale_specifics_fmv"; break;
    case "date-asc": $args['order'] = "ASC"; break;
    default: /* No need to set arguments here as wp query defaults */ break;
}

$selectedsortby[$_SESSION['prop_selectedsortby']] = " selected=\"selected\"";
?>

Search Results

<?php
if( ! empty( $_SESSION['s_property_ptype'] ) ) {
    $args['meta_query'][] = array(
        'key' => 'chb_homes_for_sale_types_nbrs',
        'value' => $_SESSION['s_property_ptype']
    );
}

if( ! empty( $_SESSION['s_property_development'] ) ) {
    $args['meta_query'][] = array(
        'key' => 'chb_homes_for_sale_ofdevelopment',
        'value' => $_SESSION['s_property_development']
    );
}

if( isset( $_SESSION['s_property_area'] ) && 0 != $_SESSION['s_property_area'] ) {
    $args['tax_query'][] = array(
        'taxonomy' => 'areas',
        'field' => 'id',
        'terms' => array( (int) $_SESSION['s_property_area'] ),
    );
}

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_bedrooms',
    'value' => $_SESSION['s_property_bedrooms_min'],
    'compare' => '>=',
    'type' => 'SIGNED'
);

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_bedrooms',
    'value' => $_SESSION['s_property_bedrooms_max'],
    'compare' => '<=',
    'type' => 'SIGNED'
);

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_bathrooms',
    'value' => $_SESSION['s_property_bathrooms_min'],
    'compare' => '>=',
    'type' => 'SIGNED'
);

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_bathrooms',
    'value' => $_SESSION['s_property_bathrooms_max'],
    'compare' => '<=',
    'type' => 'SIGNED'
);

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_fmv',
    'value' => $_SESSION['s_property_min_price'],
    'compare' => '>=',
    'type' => 'SIGNED'
);

$args['meta_query'][] = array(
    'key' => 'chb_homes_for_sale_specifics_fmv',
    'value' => $_SESSION['s_property_max_price'],
    'compare' => '<=',
    'type' => 'SIGNED'
);
?>

List Layout
Just a standard WP loop to show post excerpts and info.

Related Posts:

  1. Advanced search form with filters for custom taxonomies and custom fields
  2. Admin Area Custom Type Search By Meta Fields Without Title & Content
  3. How do I Paginate Search Results for Custom Post Types?
  4. Search everything (posts, pages, tags, cpt, meta)
  5. WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
  6. search also in taxonomy, tags and custom fields
  7. Custom Taxonomy Search result page
  8. Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
  9. Search CPT Title AND Meta
  10. WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
  11. Custom Post Type meta data getting deleted on bulk editing taxonomies
  12. Extending the search context in the admin list post screen
  13. Include custom taxonomy term in search
  14. what is the correct way to compare dates in a WP query_posts meta_query
  15. How to Add Custom Fields to a Custom Post Type?
  16. How can I change the admin search posts fields?
  17. Development of a WordPress Search Plugin – Best Practices
  18. Custom field values deleted when trashing custom post type
  19. How to get all custom fields of any post type
  20. Search multiple custom fields by using meta_query
  21. What should I use – Taxonomies, custom fields, Post Type?
  22. Search that will look in custom field, post title and post content
  23. clients list using wordpress
  24. Custom Taxonomy Template Post List with Sort Order
  25. How to replicate some of Drupal Views functionality in WordPress?
  26. Creating Photo Gallery System with Custom Post Type
  27. Exclude from search all custom posts which are NOT in a taxonomy term
  28. How Can I save multiple records in same meta key?
  29. Exclude a term of a taxonomy with a custom post type in a search
  30. How to do a custom bookmarks post type?
  31. Detect meta value changes when post is updated (post_updated)
  32. Search Custom Post Type with all meta attached?
  33. Custom search for custom post type, custom meta and search fields
  34. How to select one major category (or custom taxonomy) for a custom post type?
  35. How Do I Use WP_Query to Run This Database Query as Search Result?
  36. updating one custom meta field only
  37. Add a class to post_class if more than one post shares same meta_value_num
  38. How to display posttypes and taxonomy in standard posts, not in a separate label?
  39. Making a form for user to add new custom post with custom taxonomies and custom fields
  40. Add a meta field to the list of results for a custom post type
  41. Should i use custom post type for a custom footer?
  42. best way to use custom taxonomy, post type and meta in a job system
  43. Empty meta-box returns publishdate if no value is set?
  44. Order custom posts by taxonomy, then by meta_key
  45. Confusion about how to use Custom Post Types, Custom Taxonomy or Category?
  46. Displaying Posts Using a Custom Query with a Custom Field and a term_id
  47. Writing a custom Glossary plugin
  48. Filter search posts by post meta?
  49. How do I ensure that post_type and Taxonomy use the same slug?
  50. add_filter get array data before display in custom post_type
  51. Custom fields for post or terms which don’t update on post update
  52. How to Implement Search Functionality?
  53. How to have multiple search result pages in wordpress with taxonomy terms listed
  54. Custom taxonomy terms as children of multiple custom post types
  55. ACF – Retrieve custom taxonomy from a relationship field
  56. Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
  57. Display Posts that fit a certain criteria on Category pages
  58. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  59. How to keep custom post type related information
  60. Display Custom Field or Custom Taxonomy in front page /post/product
  61. wp_insert_post deleting previous post custom meta
  62. How can I add a meta[] to my custom post type and search by term with the Rest API?
  63. Show posts from WP Custom Post Type selected from a field in a metabox
  64. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  65. Where is get_post_meta value located?
  66. PHP Warning with Custom Fields
  67. Custom meta fields not showing up in WP_Response Object via custom endpoint
  68. I want to create a metabox under custom taxonomy
  69. Live search by custom tag
  70. Adding a Section for Visitors
  71. How to Disable option of meta field if that option is selected for any other post in custom post type?
  72. Custom search for a custom post type in WordPress
  73. Advanced search form with multiple custom fields
  74. Query posts by multiple custom fields
  75. Custom taxonomy template for custom fields loop [closed]
  76. Saving Child Terms on front end not setting parent
  77. Order posts by meta value hiding posts instead of re-ordering
  78. Add more custom fields when creating a new custom post type
  79. Search facility with directories
  80. Create Inclusions and exclusions
  81. custom search results – order results differently by post type
  82. How do I extract the contents of a CPT’s custom field for all posts?
  83. What’s the most efficient way to get two queries based on an if statement?
  84. Need some suggestion/help with custom post types project
  85. Best way to use Category & Custom Fields?
  86. Delete custom post type metadata without deleting the post in admin area
  87. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  88. Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
  89. How to add post reference field to a plugin?
  90. Extensive search filtering and results->PDF in the front-end
  91. Search form to find custom meta box generated data
  92. WordPress custom post type
  93. predefined custom field on registration page
  94. Values inside a custom field to determine which category posts to display
  95. Show Custom Post Type taxonomy term that matches custom field
  96. Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
  97. custom taxonomies are not showing up in get_taxonomies
  98. Is it good practice to search for custom posts based on custom field values?
  99. Storing/querying custom date data
  100. Order by custom field attribute
Categories custom-post-types Tags custom-field, custom-post-types, custom-taxonomy, post-meta, search
Creating Multiple Admin Widget Page with Calling One Sidebar
Search Woocommerce product titles only

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress