Any Suggestions guys.. please help.. my question was the text fields search is only searching in wp core fields only not in custom fields data. i want it should be searched in all fields present in the post.
Hi Amol,
Sorry for the slow reply I’ve been on annual leave. It’s not possible currently to build what you need using this plugin straight out of the box. It’s a good idea though and I will add this on to the list for a future release.
If you are confident with php you may be able to add this functionality yourself. You would need to write a new sub-class of WPCustomFieldsSearch_DataType
(some examples are in the file datatypes.php
) and then register your new class using the filter wp_custom_fields_search_datatypes
.
If you need this functionality urgently and would like to fund it’s development please let me know.
Thanks,
Don
Hi Don,
Thanks for the reply. sorry for bothering you in the middle of your annual leave, i tried to build a function which will extend WPCustomFieldsSearch_DataType but and wrote some code but no luck.. it’s showing nothing found error in search results. can you give some more hint or example or if you can send me your invoice on [email protected] so once I pay you can send me the code.
Just one request if decided to charge me then add this option as paid in your future release.. π
Below is my function, please dont laugh if anything stupid written.
class WPCustomFieldsSearch_Customallresult extends WPCustomFieldsSearch_DataType {
function get_name(){ return __("Custom All Result","wp_custom_fields_search"); }
function getFieldMap(){
global $wpdb;
return array(
"customallresult" => __("customallresult","wp_custom_fields_search"),
);
$results = $wpdb->get_results("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta ORDER BY meta_key");
$fields = array();
foreach($results as $result){
$fields[$result->meta_key] = $result->meta_key;
}
return $fields;
}
function getAvailableFields(){
return array_values($this->getFieldMap());
}
function get_table_name(){
global $wpdb;
return $wpdb->postmeta;
}
function get_field_aliases($config,$count){
if($config['datatype_field']=='all'){
$aliases = array();
foreach(array('post_title','post_author','post_content') as $field){
$aliases[] = $this->get_field_alias($config,$field,$count);
}
return $aliases;
} else {
return parent::get_field_aliases($config,$count);
}
}
function get_field_alias($config,$field_name,$count){
return $this->get_table_alias($config,$count).".meta_value";
}
function add_joins($config,$join,$count){
$join = parent::add_joins($config,$join,$count);
for($a = 0 ; $a<$count ; $a++){
$alias = $this->get_table_alias($config,$a);
$join = str_replace("AS $alias ON ","AS $alias ON $alias.meta_key='".wpcfs_escape_string($config['datatype_field'])."' AND ",$join);
}
return $join;
}
function get_suggested_values($config){
global $wpdb;
switch($config['datatype_field']){
case 'customallresult':
$values = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key=%s ORDER BY meta_value",$config['datatype_field']));
return $this->_array_to_suggestions_list($values);
}
}
}
-
This reply was modified 4 years, 7 months ago by
Amol Sawant.
Hi Don,
Still waiting for your reply.. please reply mate..
as your answer is dependent upon our(Me and my other colleague) pandemic job in india.
Thanks
Hi Amol,
Sorry for the slow reply. I’ve been a little busy and haven’t had time to read through your code.
I’ll get back to you properly tomorrow.
Thanks,
Don
Hi Amol,
I’ve put together a simple plugin which I think should do what you need. It allows you to search for content in any custom field, plus a list of post fields (including title, content etc.)
The plugin is here if you want to give it a try: https://www.don-benjamin.co.uk/files/search-everything.zip
I haven’t included this in the main plugin as there isn’t really a nice way to do it with the current architecture, I think this should work for your purposes but it’s not really searching everything so wouldn’t work for someone with a different database setup.
There is a significant rewrite of the plugin coming soon (when I get some time) and I will aim to cater for this requirement in the rebuild.
If the plugin works for you, feel free to make a donation and rate the plugin here: https://wordpress.org/plugins/wp-custom-fields-search/
Thanks,
Don