WP Custom Fields Search v 0.2 beta

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.7

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.
  2. 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
  3. You should now have a basic search from on the front of your site, to customise this further read on to see how to reconfigure your 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.

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..

Changes since v0.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: , , , 16 comments »

16 Responses to “WP Custom Fields Search v 0.2 beta”

  1. Rowan

    Heya – looks like a great plugin, is there a way that it could be called in a theme not using a widgets? like just a line of php that could be put into a custom page template?

    cheers!

  2. Don

    Not at present because all the config is done through the widgets part of the admin section. I was planning to put in a preset option where a form could be configured through a plugin config page (rather than widget config) then re-used in multiple sidebars, so when I do this I could put in an option to pull in presets through the template. I’m going to put up a new release tomorrow, mostly for compatibility with older wordpress versions, but if that functionality would be a priority I can try to bring it forward. If it doesn’t make it into tomorrow’s version it will be available soon.

    Thanks, Don

  3. ibrahim

    Hello,
    it is a great plugin, it is what i have been exactly looking for. But with one major feature; like Rowan, I need to use it not in the widget but by embedding a page.
    Looking forward for the tomorrow release.

    Thanks again
    ibrahim

  4. Don

    The new version, with preset functionality is now up:

    http://www.don-benjamin.co.uk/wordpress/projects/foss/wp-plugins/wp-custom-fields-search-03/

    I probably need to tidy it up a bit, but the basic functionality should be there.

    Let me know what you think.

    Don

  5. How to Get Your Ex Back

    After reading through the article, I just feel that I really need more info. Can you share some more resources please?

  6. Rotten Monkey

    This seems like it would be a potential solution to my problem. I have a site with 100,000 posts. All using several custom fields (between 8-10 each). I am currently using the SEARCH EVERYTHING plugin, which worked great when I only had about 40 posts, however, since the completion of the site, search queries now take anywhere between 20-30 seconds to complete. Far too long.

    Currently, the only search capabilities that i need are the following:

    Post Title
    Custom Field Values
    Categories

    So, now that you understand my scenario, I have two quick questions….

    1) Can your plugin handle this type of search and not take 20-30 seconds to complete the query and deliver the results to the user?

    2) Is there a script that I can simply embed into the search.php files rather than have a widget search box? I am looking for a solution to input directly into the current search bar on my site.

    Thanks in advance for any help you can give.

  7. vimal

    I have tried to integrate custom-field search plugin and also there i have integrate wp-pagin plugin, now issue is that when i got result on more than 5 post than by paging next link will highlight but when i click on that next link or page number it will give me 0 result found. any solution if possible.

  8. zero

    ok… =)

  9. Plantillas para wordpress

    I have found sites provide reviews of WordPress themes but very few of them offer SEO review of WordPress themes. Any of you know a site which offers tons of WordPress theme review in the SEO aspect?

  10. Siva

    Hi,

    Show/Hide Config button is not working. When I click it nothing opens.Any idea why?

  11. Maria

    Great plugin, i’ve used in with several websites. I’ve only had 1 issue with this plugin, the show/hide Config button sometimes does not work. I’ve tried disabling all other plugins on the site but have been unable to fix the problem.

    Has anyone else had this problem? Is there a workaround?

    And a big thanks to Don for his work on this plugin.

  12. thoi trang cung mua

    They know what their priorities in life are.

  13. trading server

    This is actually great! Thanks and also keep up the fantastic creativity.

  14. Is The Six Figure Mentors a Scam

    Hello, I would like to subscribe for this weblog to get most up-to-date updates, thus where can i do it please help out.

  15. ninary pilot Binary options

    Wow, thos article iis nice, my sister is analyzing these kinds of
    things, therefore I am going to iform her.

  16. Patrick Fragel Lawyer

    Hi friends, how is everything, and what you wish for to say about this
    post, in mmy view its actually awesome designed ffor me.


Leave a Reply



*

Back to top