Is there a kind of “search in results after you retreived all entries” thing? Thing is: I have this query: craft.entries.section('players').limit(null) I want to show all entries where playerPosition = goalie. And on the same page, I want to show all players where playerNationality = Nederlands. And on the same page I want to show the longest player (sorted by playerHeight).

I can off course run a query 3 times:

goalies = craft.entries.section('players').playerPosition('goalie').limit(null)
nationalplayers = craft.entries.section('players').playerNationality('Nederlands').limit(null)
longest = craft.entries.section('players').order('playerLength desc').first();

That would work, but I'm running a query 3 times on the same section. There must be a better way, right? – Some have told me about the SuperSort plugin (which was indeed the right solution for my previous question), but that only sorts results. It's not a real filter.

1 Answer 1


You've got your two obvious choices nailed down. You're either offloading the filtering to MySQL (running 3 separate queries so that MySQL filters the data) or you're grabbing all of the data and filtering it on the Twig/PHP side.

Which one is more performant likely depends on 1) how much data you're talking about and 2) your environment (resources allocated to MySQL vs. PHP).

For your particular case, I'd enable devMode and analyze the performance metrics between the two methods while taking into account how fast the data might increase in the future and make an educated guess based on that information.

  • And how would I do this in Twig? The first thing think of is looping through all entries and do an if/else in the loop ({% if playerPosition = "goalie" %}do stuff{% endif %}). Would that be correct? Commented Sep 6, 2016 at 6:35
  • @BartRylant yup, that's what I was thinking!
    – Brad Bell
    Commented Sep 6, 2016 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.