0

I'm building a feed of entries mixed from different sections. One section contains a postDate and a custom field date called releaseDate. I want these entries to appear in the feed with their postDate, but when the releaseDate is equivalent to now I want the entry to return in the feed in order of appearance. Is this possible?

I've tried something like this:

craft.entries.section(['section1', 'section2']).order(['postDate DESC', 'releaseDate DESC'])
4
  • I'm not sure I'm following. Can you give some sample data and how you'd like it to ultimately output?
    – Brad Bell
    Commented Nov 9, 2014 at 19:54
  • I'm building a feed for games on a news site, each game has a postDate as in when it's announced and a releaseDate for when the game is actually released. The games are presented in a feed combined with related news posts, also with a postDate. The feed is initially ordered by the postDate. So for example you have a feed looking like this: Call of Duty Advanced Warfare is announced -> Some news entry -> Some news entry -> Call of Duty Advanced Warfare is out now!. So I would like to repeat the game entry within the feed from the point when it is released.
    – Hasco
    Commented Nov 9, 2014 at 20:07
  • So "Call of Duty Advanced Warfare" and "Call of Duty Advanced Warfare is out now" are the same entry, you've just updated the title? Or they are two separate entries?
    – Brad Bell
    Commented Nov 9, 2014 at 20:47
  • They are the same entry with the same title, the "is out now" part will be added in the front-end. I want to apologize for the vagueness of my question, it's kinda hard to explain.
    – Hasco
    Commented Nov 9, 2014 at 21:06

2 Answers 2

2

You could probably do this purely from Twig / a template, but I think it's going to end up being much easier from a plugin / PHP.

The general gist of it would be:

  1. Grab all entries from section 1 ordered by postDate.

  2. Grab all entries from section 2 ordered by releaseDate.

  3. Create a new array and loop through 1 and 2 inserting via your custom sorting logic.

  4. Return that new sorted array back to the template.

1

As an alternative, you could also simply create the first entry as usual, setting the post date to the post date. Then use a plugin like AM Command to duplicate the entry, add 'is out now!' to the title, alter any other content as needed, and set the post date to the release date. This would give you a lot more flexibility regarding title and content, etc., and without the need for a custom plugin. The game entry itself could even be in an entirely separate channel and pulled into any news related to it via a related entries field. This would allow you to create other news events as well, such as 'release delayed!', etc.

3
  • Thank you for your answer! Although this is not exactly the solution I'm looking for since I would only like to display one entry twice and not create a duplicate entry. So I think I'll have to go with Brad's solution for my specific problem.
    – Hasco
    Commented Nov 10, 2014 at 13:42
  • Of course. No problem. I just thought I would throw out some other options for you to consider. Keep in mind, you can also have an article that has no body and just dynamically pulls in content from the other article (even from the same channel) via related entry. So no duplicate. Just the title and post date (aka release date). I've used this kind of article linking in some of my projects and seems to work really well. Basically, lots of options. Commented Nov 10, 2014 at 16:05
  • Thanks, I was thinking of similar kind of approach if other options run short. I'll have to figure out what suits the purpose best, maybe even by trial and error.
    – Hasco
    Commented Nov 10, 2014 at 18:37

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.