• Hello I need help with your plugin.

    before, a really nice plugin – I like it and buy the startup.

    i have put in a custom field named Ortschaften ..

    function search_by_ortschaften_form_load( $form ) {
        
        if( $form['name'] != 'search' ) {
            return $form;
        }
        $form['field'][] = array(
            "name" => "ortschaften",
            "type" => "adverts_field_select",
            "order" => 20,
            "label" => __("", "adverts"),
            "max_choices" => 10,
            "options" => array(
                array("value"=>"Aarwangen", "text"=>"Aarwangen"),
    			array("value"=>"Bützberg", "text"=>"Bützberg"),
                array("value"=>"Eriswil", "text"=>"Eriswil"),
    			array("value"=>"Herzogenbuchsee", "text"=>"Herzogenbuchsee"),
    			array("value"=>"Huttwil", "text"=>"Huttwil"),
    			array("value"=>"Kleindietwil", "text"=>"Kleindietwil"),
    			array("value"=>"Langenthal", "text"=>"Langenthal"),
    			array("value"=>"Leimiswil", "text"=>"Leimiswil"),
    			array("value"=>"Lotzwil", "text"=>"Lotzwil"),
    			array("value"=>"Madiswil", "text"=>"Madiswil"),
    			array("value"=>"Murgenthal", "text"=>"Murgenthal"),
    			array("value"=>"Roggwil", "text"=>"Roggwil"),
    			array("value"=>"Rohrbach", "text"=>"Rohrbach"),
    			array("value"=>"St. Urban", "text"=>"St. Urban"),
    			array("value"=>"Wynau", "text"=>"Wynau"),
    			array("value"=>"Wyssachen", "text"=>"Wyssachen"),
            ),
            "options_callback" => "",
            "meta" => array(
                "search_group" => "visible",
                "search_type" => "half" 
            )
        );
        return $form;
    }

    How must be the query for Search?

    I have a code, but its for taxonomies..

    add_filter( 'adverts_list_query', 'search_by_ortschaften_query' );
    /**
     * Adds tax_query param to WP_Query
     * 
     * The tax_query is added only if it is in $_GET['advert_category']
     * 
     * @param array $args WP_Query args
     * @return array Modified WP_Query args
     */
    function search_by_ortschaften_query( $args ) {
        
        if( ! adverts_request( "ortschaften" ) ) {
            return $args;
        }
        
        $args["tax_query"] = array(
            array(
                'taxonomy' => 'ortschaften',
                'field'    => 'ortschaften',
                'terms'    => adverts_request( "ortschaften" ),
            ),
        );
        
        return $args;
    }

    Can you help?

Viewing 1 replies (of 1 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    in order to search by the ort meta you would need to change the below code

    
    $args["tax_query"] = array(
        array(
            'taxonomy' => 'ortschaften',
            'field'    => 'ortschaften',
            'terms'    => adverts_request( "ortschaften" ),
        ),
    );
    

    to

    
    $orts = adverts_request( "ortschaften" );
    if( ! is_array( $orts ) ) {
      $orts = (array)$orts;
    }
    $args["meta_query"][] = array(
      'key' => 'ortschaften', 
      'value' => $orts, 
      'compare' => 'IN'
    );
    
Viewing 1 replies (of 1 total)

The topic ‘custom field search query’ is closed to new replies.