tags:

views:

94

answers:

1

Hi All,

I am using addAttributeToFilter but it is retrieving the wrong result:

$collection->addAttributeToFilter(array(
        array(
            'attribute' => 'Author_first_name_1',
            'like'        => "%" . 

trim(Mage::helper('catalogsearch')->getQuery()->getQueryText()) . "%",
            ),
        array(
            'attribute' => 'Author_surname_1',
            'like'        => "%" . 

trim(Mage::helper('catalogsearch')->getQuery()->getQueryText()) . "%",
            )
    ));

Here, I am trying to get the result whose first name or last name match with query string, but not getting the correct result. If I remove first name condition from here then it is working fine. Can any one help me?

Thanks in advanced Hiral

A: 

Hi All,

I got the solution... this may be helpful to others. It should be like this:

$collection->addAttributeToFilter(array(
                    array('attribute'=>'Author_first_name_1', 
                            'like'=>'%'.Mage::helper('catalogsearch')->getQuery()->getQueryText().'%'
                    ),
                    array('attribute'=>'Author_surname_1', 
                            'like'=>'%'.Mage::helper('catalogsearch')->getQuery()->getQueryText().'%'
                    ),                  
                ), '', 'left');

happy coding Hiral