Support » Plugin: WP Custom Fields Search » Search text box not working

  • Amol Sawant

    (@amolsawant1989)


    Hello team,

    The plugin is just awesome. everting is perfectly fit for us but only thing which is not working is as follows,

    so we have used 9 ACF fields in our post.

    In search page
    we have used 4 ACF fields for search – 3 are ACF dropdowns(which are perfectly working) and 1 is for text input. whenever we enter anything which other ACF fields are contained it’s not working.
    Please check, you need to login into to check that page u need to login and following are credentials as both contain “amoluser”

    Please help.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Amol Sawant

    (@amolsawant1989)

    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.

    Plugin Author don benjamin

    (@dondon-benjamincouk)

    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

    Thread Starter Amol Sawant

    (@amolsawant1989)

    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 amolsawant1989@gmail.com 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.. 🙂

    Thread Starter Amol Sawant

    (@amolsawant1989)

    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 1 year, 11 months ago by Amol Sawant.
    Thread Starter Amol Sawant

    (@amolsawant1989)

    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

    Plugin Author don benjamin

    (@dondon-benjamincouk)

    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

    Plugin Author don benjamin

    (@dondon-benjamincouk)

    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Search text box not working’ is closed to new replies.