Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • virteer Friend
    #159727

    Heres a tricky one for you!

    How can we order the results by a certain K2 Extra Fields?

    Say we have dropdowns for Title, Location, Price.
    If I search by Price, you would expect the results to show the items in order of price (either lowest to highest or highest to lowest).

    I’m gonna try modifying the default_results.php to get this working.

    Any tips would be greatly appreciated!
    Consider this a feature request 🙂

    Anton

    thuanlq Friend
    #375847

    Hi @virteer,

    you can set order the results by a certain k2 extra fields, please do as following:
    – Open file “jak2_filter.php” in the folder “pluginssearch”.
    – Change some lines code of “onSearch” function


    function onSearch($text, $phrase = '', $ordering = '', $areas = null)
    {

    ...
    /*Add your code here to check k2 extra fields to get order by different fields.*/
    /*Change $ordering variable*/
    ...
    }

    default check order by of this function:


    ..
    switch ($ordering) {
    case 'oldest':
    $query.= 'ORDER BY i.created ASC';
    break;

    case 'popular':
    $query.= 'ORDER BY i.hits DESC';
    break;

    case 'alpha':
    $query.= 'ORDER BY i.title ASC';
    break;

    case 'category':
    $query.= 'ORDER BY c.name ASC, i.title ASC';
    break;

    case 'newest':
    default:
    $query.= 'ORDER BY i.created DESC';
    break;
    }
    ...

    Good luck!

    virteer Friend
    #376603

    This was my initial thinking too.
    However, since I want to search by the Extra Field I can’t use the ordering here.
    It should be done within the default_results.php of the Joomla search component.
    But this is all getting very messy, JA K2 Filter & Search really needs its own unique search component.

Viewing 3 posts - 1 through 3 (of 3 total)

This topic contains 3 replies, has 2 voices, and was last updated by  virteer 13 years, 3 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum