Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter d2eck

    (@d2eck)

    Oh, i found it, i replace ‘LIKE’ to ‘IN’! Now it works!
    Last quastion, is there any way, to translate (i have multilanguage site) words “One”,”Two” and “Custom fields” LOCO translate does not see this words. (And other Lables that are written “by hand” in function.php)

    Thanks, best regards!

    Thread Starter d2eck

    (@d2eck)

    Checkbox appears in add form, and in search form. But it does not search, when i set “One” or “Two”. May be i made mistake, all code is:

    add_filter( "adverts_form_load", "my_adverts_form_load" );
    	
    	function my_adverts_form_load( $form ) {
    	
    	if( $form["name"] != "advert" ) {
    	return $form;
    	}
    		$form["field"][] = array( 
    	"name" => "my_custom_checkbox",
    	"type" => "adverts_field_checkbox",
    	"order" => 2,
    	"label" => "Custom Checkbox",
    	"is_required" => false,
    	"validator" => array( ),
    	"max_choices" => 2,
    	"options" => array(
    	array("value"=>"1", "text"=>"One"),
    	array("value"=>"2", "text"=>"Two"),
    	)
    	);
    	
    	return $form;
    	}
    add_filter( 'adverts_list_query', 'search_by_custom_checkbox_query' );
    function search_by_custom_checkbox_query( $args ) {
        if( ! adverts_request( "my_custom_checkbox" ) ) {
            return $args;
        }
        $args["meta_query"][] = array(
            'key'=> "my_custom_checkbox", 
            'value'=> adverts_request( "my_custom_checkbox" ), 
            'compare'=> 'LIKE'
        );
        return $args;
    }
    add_filter( 'adverts_form_load', 'search_by_custom_checkbox' );
    function search_by_custom_checkbox( $form ) {
        
        if( $form['name'] != 'search' ) {
            return $form;
        }
        $form['field'][] = array(
            "name" => "my_custom_checkbox",
            "type" => "adverts_field_checkbox",
            "order" => 20,
            "label" => __("Category", "adverts"),
            "max_choices" => 10,
            "options" => array(
                array("value"=>"1", "text"=>"One"),
                array("value"=>"2", "text"=>"Two"),
            ),
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "full" 
            )
        );
        return $form;
    }
Viewing 2 replies - 1 through 2 (of 2 total)