Magento2 – How to Enable Advanced Search for Custom Attribute

custom-attributesmagento2

I have create custom attribute programatically, these are the fields,

  $eavSetup->addAttribute(

        \Magento\Catalog\Model\Product::ENTITY,
        'myattribute',/* Custom Attribute Code */
        [
            'group' => 'Product Details',/* Group name in which you want to display your custom attribute */
            'type' => 'text',/* Data type in which formate your value save in database*/
            'attribute_set' =>  'myattribute',
            'backend' => '',
            'frontend' => '',
            'label' => 'Address', /* lablel of your attribute*/
            'input' => 'textarea',
            'class' => '',
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'visible' => true,
            'required' => false,
            'user_defined' => true,
            'default' => '',
            'searchable' => true,
            'filterable' => true,
            'comparable' => false,
            'visible_on_front' => true,
            'used_in_product_listing' => true,
            'unique' => false
        ]
    );

I need to enable Advanced Search while creating Custom Attribute in programatically, if i set 'searchable' => true' only enable Use in Search field, but not enable Visible in Advanced search.

Reference:

enter image description here

Suggest me How to enable this programatically.

Best Answer

below line do the trick of enable Visible in Advanced search

'visible_in_advanced_search' => true,
Related Topic