List items with search Class

Osclass search class allows you to filter the items and display only the items that match your search criteria. 

Let say that you want to display on the home page or on any other page the items from a location or a specific user or based on search criteria, you can use the built in  search function to display those type of items.

$mSearch = new Search();

$mSearch->limit(10);

$aItems = $mSearch->doSearch();

$iTotalItems = count($aItems);

View::newInstance()->_exportVariableToView('items', $aItems);

while (osc_has_items()) {

    echo osc_item_title() . '<br />';

}

Add a region in search

$mSearch->addRegion('your-region-name');

Add a category in search

$mSearch->addCategory('your-category-id');

You can see more in oc-includes/osclass/controller/search.php. 

Here you can see how the search is made for search page and how all the filters are applied.

Now the filters together to get the similar item on item page

$mSearch = new Search();

$mSearch->addCategory(osc_item_category_id());//category

$mSearch->addRegion(osc_item_region());//region filter

$mSearch->addItemConditions(sprintf("%st_item.pk_i_id < %s ", DB_TABLE_PREFIX, osc_item_id()));//exclude the current item

$mSearch->limit(10);//limit the results

$aItems = $mSearch->doSearch();

$iTotalItems = count($aItems);

if ($iTotalItems > 0) {

    View::newInstance()->_exportVariableToView('items', $aItems);//export items

    while (osc_has_items()) {

        echo osc_item_title() . '<br />';//item title

    }

}

 

Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.