WP Custom Fields Search 0.3

Front End ScreenshotThis is my search plugin for wordpress, designed to filter posts in a more structured way than the default wordpress search. Specifically it allows multiple form inputs to be configured to search different aspects of a post, i.e. one term could search the post content, one the post title and one could search a custom field associated with the post.

The blog admin is able to build a customised search form. It allows you to search by the standard post information and by custom fields and to choose what HTML form elements should be presented for each search field.

I originally developed this plugin for a client project. Basically the problem they had was that they were storing real estate data as wordpress posts with associated custom fields and they wanted to search for entries based on price, location and features which was not possible with the default wordpress search.

The plugin is now at point where I think it could be useful to other people although I’m aware that there are a lot of improvements that could be made. Please let me know if you have any suggestions or complaints and I will do my best to get them resolved.

You can download the plugin here.

System Requirements

I have tested with the following software versions, other versions may or may not work.

  • PHP Versions 4.4.9 and 5.2.6
  • WordPress 2.5, 2.7 and 2.7 MU

Quick Start Guide

I will try to put more complete documentation together at some point but for now this is a quick start guide to building a search form.

  1. Install the plugin. Download it here unzip it in your wp-content/plugins folder, then activate it in the plugins > installed page of your wordpress admin site.

Method 1: Add the search as a sidebar widget

  1. Add the widget to the sidebar on which you want it to appear. Go to the appearance > widgets section of the admin page, in the list on the left find the widget “Custom Fields Search” and click the add button next to it. It should appear in the list on the right. Click save changes
  2. You should now have a basic search form on the front of your site, to customise this further read on to see how to reconfigure your fields.

Method 2: Add the search code directly into your template

  1. Go to the custom fields config page in your admin section, Settings > WP Custom Fields Search
  2. Copy the example PHP code from this page into your template file.
  3. You should now have a basic search form on the front of your site, to customise this further follow the instructions below for setting up fields.

Setting up the fields

Admin Screenshot

Admin Screenshot

Each field has a number of settings which control the way the input appears to the user and the way the search is performed. Most of the settings are hidden when you first go to edit the widget and you will need to click the show/hide config button to get access to many of the parameters.

Label sets the label displayed next to the field, you can set this to whatever you want.

Data Type controls what type of data is being searched (i.e. what database table is being used). The standard options are “Post Field” for data such as post title and post content, from the standard wordpress post data, “Custom Field” for data from the custom fields, and “Category” to search on the categories a post is in.

Data Field makes a more specific selection from the data available. The drop down list should give some sensible options, or if you know the name of the database field you want to query you can type this in manually.

Widget controls what type of HTML input is created for the front end of the site. It should be fairly obvious what these do.

Some widgets will require extra options in the Widget Options field. At the moment this is just the drop down and radio button widgets which allow you to specify a list of values for the user to choose from. If you leave the options blank then they will be automatically populated with a list of all values currently in the database, this can be useful for fields like categories and tags, but is less useful for fields like title which would just generate an entry for every post in the blog. If you want to specify the values manually you can specify this as a comma separated list of values, ‘a,b,c’ for three options with values ‘a’, ‘b’ and ‘c’ respectively, or if you want to give ‘friendly’ labels to the user you can separate the value from the label using a colon as follows ‘a:Group A,b:Group B,c:Group C’.

The Compare field controls the way that the user input is compared to the data in the database. I would expect the most commonly used of these to be “equals” which requires an exact match between the user data and the database field (useful for category searches) and the “Words in” or “Phrase In” types which will search to see if the user input is a part of the data, rather than a full match, this is useful for things like searching the text of a post. The difference between ‘words’ and ‘phrase’ is that ‘words’ splits the input into a series of words and searches for these individually whereas ‘Phrase’ searches for all the words in sequence.

The “Less Than” and “More Than” comparisons ensure that the data is less than or more than the user input respectively. This is probably only relevant for numeric input but it can be used for strings as well and will search alphabetically. For numeric input it can help to also tick the “Numeric” checkbox as sometimes the database will be set up to compare numbers alphabetically (so that 10 is less than 2).

The “Range” comparison is a little more complicated and requires the user input to be of the form A-B to return results that are between A and B. This is primarily intended to be used for Drop-downs and radio buttons where the values can be set by the site administrator. If you specify the values for the dropdown like the following: “-10:Less Than 10,10-20:Between 10 and 20,20-:More than 20”, then the user will be presented with the options “Less Than 10”, “Betwen 10 and 20” and “More than 20” but the search will be done with the values “-10″,”10-20” and “20-“. Again the numeric checkbox should be used for numeric data.

I hope that helps, please let me know if you have any trouble (or joy) with the plugin or if any of my instructions don’t make sense.

Using Presets

Presets are a new feature in version 0.3, they allow search forms to be configured separately from the sidebar widgets, the configured form doesn’t directly appear on the site but can be included in two ways.

Firstly, by copying and pasting the php code from the preset config page into a template file you can place a search form anywhere you want in your template.

Secondly, by using a preset as the basis for another search form.  When setting up a search form you have the option of selecting one of the presets from a dropdown list.  Selecting one will include all of the fields from this preset in your form.

Presets are configured in exactly the same way as the sidebar widget, you can find the presets in the “Settings > WP Custom Fields Search” section of your admin site.

Extending Custom Search

For developers, I’ve tried to build this in a modular way to allow extensions to be added, I will try to document this at some point in the future but if you can’t wait then the best places to get started would be to look at the filter ‘custom_search_get_classes’ in custom-search/custom-search.php and the Great Real Estate bridging code in custom-search/bridges/greatrealestate.php.

This plugin is at quite an early stage in development though so it is likely that future versions may not be compatible with the same extension interface and it is likely that any extensions will need altering when new versions are released..

Changelog

Since 0.2

Since 0.1

  • I’ve reworked the UI and added some more sensible default values, hopefully this should make it less daunting for new users.
  • Fixed a few bugs.
  • Added in textual descriptions of the search parameters (for themes which support this)

Category: Wordpress Plugins | Tags: , , , 87 comments »

87 Responses to “WP Custom Fields Search 0.3”

  1. Elton Martins

    Please Help!

    The module don’t show all my custom fields when I’m creating a new form.

    How can I fix this?

    Thanks

  2. Elton Martins

    Sorry. It’s my fault.

  3. david

    my theme is not support widgets.
    How do by code I use this plugin?
    What code do I use the theme?

  4. meloniq

    RE: Ameise , RE: Gabrielle

    I had the same problem as You, with this sticky posts which appear in search results even if they do not match the search phrase…

    I wrote small solution on my blog if You still looking for it:

    http://blog.meloniq.net/2010/09/16/fix-wp-custom-fields-search-sticky-posts/

  5. pescadito

    Really a wonderful plugin!

    Just i a little css bug that i cannot reach to find: in the front page the wp-custom-field-search-widget include the first next widget inside the widget frame. i clip fixed this adding a blank text widget without title nor content and thats worked to me. I don’t explain why it didn’t reported before.

    Second nice feature to add (i only hard-coded it) is the option to specify custom post type to search in

    Thanks for your efforts, best regards, pescadito

  6. Melissa

    Hey Don,

    This is a great plugin that is very beneficial to the website that we are putting together. My only question is whether or not there is a way to make the results page only show links to pages. I’m using it to search for static pages and the results page shows the full content of each page in the results list.

    This would be quite troublesome if there were to be twenty different results that showed up at a visitor’s inquiry.

    Melissa

  7. ABCDiamond

    Is there a way to have the results sorted into alphabetical order ?

    I am using WordPress 2.9.2 and WordPress 3.0.1, (2 sites) and the plugin works, but not sure if it should be sorting or not.

  8. Nicolas

    Hello, How are you?
    Thanks for this plugin!
    How Can I change The Text that Says ANY in drop Down Menu?

    Thanks.

  9. goliv

    Can someone help me to make the “WP Custom Fields Search” working with “WPML Multilanguage” Plugin?

  10. Jason

    Hi there. Firstly, thanks for all your hard work!

    Is there a way to display the search results in a table? This would be fantastic!

    I”m sorry if this has already been asked, but I can’t find it anywhere.

    Thanks,
    Jason

  11. MACCoutinho

    Hello,

    I’m trying to translate your plug-in. So far I’ve found the “ANY” value on your code and replaced it with the appropriate value. Now I’m trying to change the text on the submit button but I’m having a harder time finding it. Maybe you should considering creating a separate options file to easily change those values or include options on the plug-in’s settings to change it there.

    Thank you!

    MACC

  12. mikou

    Hello and Thanks for this,

    What I would recommend to add, if it does not already have the feature, is the possibility to exclude some categories from any search presets or to tell it to search only one within cat, instead of entering categories as meta keys and values to go around it from a php beginner’s point of view.

    And also enable easy association of search templates with each search presets…

    cheers 😉

  13. mikou

    As per the categories inclusion/exclusion issue noted above, I found the way around it, most probably talked of elsewhere already.

    So, if you guys want your form preset to search into a specific category without having the category drop down:

    Data type: Category
    Widget: Hidden Constant
    Compare: Equals
    Constant Value: “the Name of the Category to search”

  14. nipo

    hi
    thanks for the great work it’s an amazing plugin which helped me a lot in moving from joomla to wordpress.

    i noticed one thing: when you set a static page as home page in your blog the plugin doesn’t seem to work anymore

    hopefully this could be fixed in some way

  15. Tractari Auto

    Great!
    Is there a way to add a checkbox-input?

    Thanks

  16. Eduardo dulce

    Congratulations Don.

    I have found a solution to make alphabetical search.
    You have to add this code:

    … inside the search.php of your current Theme.

    The position of the code is before “the loop”. I put here literally the code of my search.php:

    <?php
    if(have_posts()) { …

  17. Eduardo dulce

    —?php query_posts(‘orderby=title&order=ASC’); ?—

    The web cant show code. I write with out the sign of open php and close

  18. Tractari

    http://www.etractari.ro —?php query_posts(’orderby=title&order=ASC’); ?—

    try here dont work

  19. Pete

    I am wondering if there is a way to when someone selects a country that is I can program it to then have a sub category automatically populate the states within that country. Or if someone selects a state, that it then automatically populates the next search drop down to show the cities within that state or area. Is there a way to do that?

  20. gaurav

    hi there

    plugin is great… I am using plugin to search bedrooms, bathrooms and sleeps for a property website, but when bedrooms is less then or equal to 3 the form is not working… please help me out…

  21. Wes

    Just figured out how to get custom post types working:

    http://wordpress.org/support/topic/plugin-wp-custom-fields-search-not-searching-custom-post-types

    But now, I have the issue of how the plugin handles boolean searches. I need it to do a search using the “OR” operator instead of “AND.” The problem is, in order to get any results, there has to be an exact combination of radios and dropdowns selected instead of just displaying all results that contain any of the selected items.

    How can I modify the plugin to support this?

  22. pescadito

    WP Custom Fields Search is a fantastic plugin, we need to keep it alive!

    but because https://wordpress.org/support/topic/plugin-wp-custom-fields-search-not-searching-custom-post-types?replies=8 was closed,

    i add my quater here:

    for WP Custom Fields Search work with custom post type, you need add this plugins:

    ——————————————————–
    best regards,
    pescadito

  23. pescadito

    i think this plugin is un-supported and all fork to add some feature (as ‘OR’ conditional or another) will be welcomed.

    please if you do, leave a link here

  24. pescadito

    something was wrong when i submit comment number 80,
    please refer to

    https://wordpress.org/support/topic/wp-custom-fields-search-not-searching-custom-post-types?replies=1

  25. strangerrj

    Hi Don, thanks for the Plugin. This ist super perfect for me an my site.

    Thanks Greetings Rick

  26. m1234

    Hi,
    I am getting a problem with custom field search.
    only one result getting every time .tried with every mode of search like Custom post type tile, custom field ..any help for this..?

  27. Paulo Ricardo Cardoso

    Hi I use custom fields search plugin, it helps me a lot.

    I have a problem is the following, I have a category field that was created by the plugin Advanced custom field, and I want to use this field to search posts, I created a lookup field through the plugin custom search field, select it to type as the data type: custom field and the date field the field that corresponds to my categories, so far all right, the problem is that the site in the search field shows the id of the categories instead of showing the name of the category.

    I hope to answer, thank you very much.

  28. Thian

    Hi there, could you please explain how I could put the label, in the field;

    ie. Search in the field, then when user clicks on it disappears.

    Thanks in Advance 🙂

  29. ABCDiamond

    This is on the main WP Plug in site:

    This will probably be the last version of this plugin that I release, it’s not been financially viable to develop the plugin in this way and as such I have not been able to provide the level of support that I would like to. Apologies to everyone who’s emails / forum posts etc that I haven’t answered. In the near future I will be significantly reworking the plugin and re-releasing it either as a paid for plugin or free with a premium version, hopefully this should fund the time I need to put in to support and develop the project.

    However, it also shows this:

    Compatible up to: 3.5.2
    Last Updated: 2013-6-27
    Downloads: 49,815

    It does look like it has been taken over by another plugin developer at: webhammer.co.uk

  30. don

    Hi, that’s also me at webhammer.co.uk, I’ve released a few bug-fix versions since I put that note up but the plan is still to rebuild from scratch and relaunch in a different format, probably with a free version and then premium functionality available to those who can pay for it. Thanks, Don

  31. realmag777

    Good plugin to search by meta fields and taxonomies with built-in meta fields constructor http://codecanyon.net/item/wordpress-meta-data-filter/7002700?ref=realmag777

  32. GamingCast unlock telecharger

    You’ve made some really good points there.
    I checked on the net to learn more about the issue and found most people will go along with
    your views on this website.

  33. 4oliveus.com

    magnificent publish, very informative. I wonder why the opposite experts of this sector do not understand this.
    You must continue your writing. I’m confident, you’ve a great
    readers’ base already!

  34. to

    Wonderful article! This is the kind of info that
    are supposed to be shared around the net. Shame on the seek
    engines for not positioning this publish higher!
    Come on over and discuss with my web site . Thanks =)

  35. domain

    It’s an awesome paragraph in support of all the
    internet people; they will obtain benefit from it
    I am sure.

  36. Bogowie zobacz online za darmo 2014

    I do not know if it’s just me or if perhaps everybody else encountering problems with your blog.
    It appears like some of the written text within your
    posts are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as
    well? This could be a problem with my internet browser because I’ve had this
    happen previously. Thanks

  37. install openerp

    We need to consider the key elements required in a Best
    Practice supply chain design. Rise of ERP consultants with expertise in handling modules of certain ERP
    will be a new future trend in ERP consulting. ‘ (>12%) Organizational Management Configuration ‘ (>12%) Personnel Administration Configuration ‘
    (>12%) Time and Attendance Management Configuration ‘ (8-12%) Organizational
    Management ‘ (8-12%) Personnel Master Data ‘ (8-12%) Reporting and Analytics ‘
    (8-12%) SAP HCM Business Processes ‘ (8-12%) Time and Attendance Management ‘ (8-12%) Personnel Administration.


Leave a Reply



ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

Back to top