Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
There's a way to order an Auth_User by a profile field(metadata)?
  • I'm trying to list my users using custom order, and I'm trying to figure out if order by a profile field (metadata) is possible.
    Can I do this?
  • That is going to be difficult, because metadata has mutliple values, so it's going to order on all of them. It might not produce the correct results, but you can try to use

    ->order_by('metadata.value')-> ...
  • @heitorfig: If you get to manage that, please let us (or at least me) know. I was trying to do a similar thing but it didn't work.
    Well, that's not all correct. It worked to sort by a metadata's value, but then that was the only metadata being retrieved from the database and all the other metadata attributes/keys were not assigned to the user.

    So, if get this to work properly, please post an update here :)
  • I know it is a very old topic. But I was searching for the answer also.
    After some trail and error I came up with this solution. You have to know the name of the meta property to make it work. 

    $order_by = 'fullname';
    $order = 'desc';

    $users = DB::query("
          SELECT users.*,
         (SELECT users_metadata.value where users_metadata.key LIKE
         'fullname') as fullname
          FROM users
          join users_metadata on = users_metadata.parent_id
          ORDER BY $order_by $order

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion