WordPress.org

Ready to get started?Download WordPress

Forums

WP Custom Fields Search
Any updates on the checkboxes? (2 posts)

  1. mattbarry
    Member
    Posted 2 years ago #

    Has anyone managed to get the search form to work with checkboxes??

    This is the last function I need and it's driving me insane!

    http://wordpress.org/extend/plugins/wp-custom-fields-search/

  2. gorodsb
    Member
    Posted 1 year ago #

    If still actual...
    Insert in wp-custom-field-searn.php (version 0.3.16)this:
    line 237 $inputs.="<td><input type='checkbox' ".($values['numeric']?"checked='true'":"")." name='$pref"."[numeric]'/></td>";
    and on line 507

    class CheckboxField extends Field {
    function CheckboxField($options=array(),$params=array()){
    CheckboxField::__construct($options,$params);
    }
    function __construct($params=array()){
    parent::__construct($params);
    if($params['checkboxoptions']){
    $options=array();
    $optionPairs = explode(',',$params['checkboxoptions']);
    foreach($optionPairs as $option){
    list($k,$v) = explode(':',$option);
    if(!$v) $v=$k;
    $options[$k]=$v;
    }
    }
    $this->options = $options;
    }
    function getOptions($joiner,$name){
    if($this->param('fromDb',!$this->options)){
    return $joiner->getAllOptions($name);
    } else {
    return $this->options;
    }
    }
    function getInput($name,$joiner,$fieldName=null){
    if(!$fieldName) $fieldName=$name;
    $v = $this->getValue($name);
    $id = $this->getHTMLName($name);
    
    $options = '';
    foreach($this->getOptions($joiner,$fieldName) as $option=>$label){
    $option = htmlspecialchars($option,ENT_QUOTES);
    $label = htmlspecialchars($label,ENT_QUOTES);
    $checked = ($option==$v)?" checked='true'":"";
    $htmlId = "$id-$option";
    
    $options.=" $label";
    }
    return $options;
    }
    function getCSSClass(){
    return "checkbox";
    }
    function getConfigForm($id,$values){
    return "Checkbox Options";
    }
    }
    class CheckboxFromValues extends CheckboxField {
    function CheckboxFromValues($fieldName=null){
    CheckboxFromValues::__construct($fieldName);
    }
    
    function __construct($fieldName=null,$params){
    $params['fromDb'] = true;
    parent::__construct($options,$params);
    }
    function getConfigForm($id,$values){
    return "";
    }
    }
    class Comparison {
    	function addSQLWhere($field,$value){
    		die("Unimplemented function ".__CLASS__.".".__FUNCTION__);
    	}
    	function describeSearch($value){
    		die("Unimplemented function ".__CLASS__.".".__FUNCTION__);
    	}
    }
    class EqualComparison extends Comparison {
    	function addSQLWhere($field,$value){
    		return "$field = '$value'";
    	}
    	function describeSearch($value){
    		return sprintf(__(' is "%1$s"','wp-custom-fields-search'),$value);
    	}
    }
    class LikeComparison extends Comparison{
    	function addSQLWhere($field,$value){
    		return $this->getLikeString($field,$value);
    	}
    	function getLikeString($field,$value){
    		return "$field LIKE '%$value%'";
    	}
    	function describeSearch($value){
    		return sprintf(__(' contains "%1$s"','wp-custom-fields-search'),$value);
    	}
    }
    
    class WordsLikeComparison extends LikeComparison {
    	function addSQLWhere($field,$value){
    		$words = explode(" ",$value);
    		$like = array(1);
    		foreach($words as $word){
    			$like[] = $this->getLikeString($field,$word);
    		}
    		return "(".join(" AND ",$like).")";
    	}
    	function describeSearch($value){
    		return sprintf(__(' contains "%1$s"','wp-custom-fields-search'),join('"'.__(" and ",'wp-custom-fields-search').'"',explode(" ",$value)));
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic