Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Order By #31

Open
seandelaney opened this issue Feb 20, 2024 · 1 comment
Open

Using Order By #31

seandelaney opened this issue Feb 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@seandelaney
Copy link

seandelaney commented Feb 20, 2024

I'm counting views for entries. That all works fine.

My query is

{% set partsQuery = craft.entries.section('partsEntry').limit(12).with(['partImage', 'partBrand', 'partCategory']).orderBy('priorityOrder DESC, title ASC') %}

My priorities for ordering:

  • Priority order field
  • Based on total views
  • Based on title

I have set my key to be viewedPartEntry.
I have added a Field called partTotalViews and added to Part section entry type.

If I try adding orderBy('partTotalViews DESC, priorityOrder ...', I get error

Column not found: 1054 Unknown column 'partTotalViews' in 'order clause'

How can I use your plugin to order by total views too?

@lindseydiloreto
Copy link
Contributor

Great question. Unfortunately, your options may be a bit limited here.

The way to sort by most viewed typically looks more like this...

{% set partsQuery = craft.entries
    .section('partsEntry')
    .limit(12)
    .with(['partImage', 'partBrand', 'partCategory'])
%}

{% do craft.viewCount.sort(partsQuery, 'viewedPartEntry') %}

However, that directly conflicts with the orderBy parameter. Only one of those two sort methods can be applied at a time.

Perhaps you could give your users the option to change the sort order?

Long-term, we have plans to improve queries so that what you're looking for would be possible. No ETA on that, but I'll leave this ticket open in the meantime.

@lindseydiloreto lindseydiloreto added the enhancement New feature or request label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants