0

I have a Drupal 8 view where I want to sort nodes by authored year using contextual filters.

So www.mysite.com/2017

will list all nodes from 2017.

I set up the filter using 'Content: Created Year' which takes YYYY format.

But the filter is ignored.

www.mysite.com/2017 returns all years.

What did I miss?

enter image description here

1

Try adding the placeholder % to the path (in the main views UI in the middle column under "Page settings"),

e.g. something like my-view/by-year/% which will accept URLs like my-view/by-year/2019

  • Thanks. Forgot about that step. That did it. – edg Jun 21 at 20:00
  • @edg You should accept Hudri's answer as the correct one if it solved the problem. – Parag Jun 21 at 23:28
  • I spoke too soon. The % is not essential for the original problem. I scrapped the view and started afresh and it worked both with and without the %. The % is useful if you need your dynamic value in the path e.g. www.mysite.com/%/feed . Not sure what fixed it. – edg Jun 22 at 1:22
  • My problem was probably related to caching. By default, the view's tag based caching is on (under 'Advanced') so any changes I made were probably not updating. The good news is the contextual filter now works for me as advertised. Thanks Hudri for your response – edg Jun 22 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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