Monday, October 31, 2011

New Wordpress Plugin: Search Simple Fields

In one of my recent projects I had to modify the Wordpress search to include some custom fields defined with Simple Fields plugin. Then I had to add some new fields to the upload form of the Wordpress Media Gallery and also include some of them in the search. After hard enthusiastic successful work of course my code had to be commented (let's say for "business consideration") so I ended up in making a new plugin, maybe other people would really benefit of my work.

When you should use this plugin:
  • if you have registered post types
  • if you use Simple Fields plugin
  • if you created Media custom fields
How to use this plugin:
  • download it
  • install and activate it
  • a new option will appear in Settings: Search Simple Fiels
  • go to the new option
1. - list of registered post types
2. - if the Simple Fields plugin is not activated, a warning message will appear, otherwise a list of defined field groups will be displayed
3.a. - if a function (see 3.b.) is defined for media custom fields, the defined fields are listed. For each field the user must insert the name of the option with which the field is saved in wp_postmeta table
3.b. - function used for Media custom fields (, for example insert in the Custom function field value xxx_custom_fields_function_name if you have in functions.php of your theme something like this: add_filter("attachment_fields_to_edit", "xxx_custom_fields_function_name", null, 2); )

To include the selected fields in the front wordpress search, add to your theme function.php file the lines below:

if(!is_admin()) :
   if(function_exists('search_simple_fields_search_posts')) :

Note: for Media type items the result of the search will be the posts (any type of registered post types which were initially included in the search query) it is attached to.

No comments: