4

I'm using the JSON plugin from Devotee to write a small API for a third-party.

Another developer (honestly) has added a 'start_date' custom field for when a particular offer is valid from. The 'entry_date' field is defaulting to the date the entry is added.

Is there a way of doing something similar to 'show_future_entries' but with a custom field? I only want entries to be returned where the start_date is before today/current_time.

Here's my simple JSON template code:

{exp:json:entries 
channel="offers" 
search:product_category="Food - chilled-dairy" 
show_future_entries="no" 
fields="title|offer_start_date|offer_end_date|product_image|product_weight|product_offer_message|
product_offer_image|...snip"}

Thanks in advance,
Brett

3

I've struggled with this problem in the past, and there's not really a native way to fix this. There are two third-party solutions that I'm aware of that will give you an easy fix:

Low Events: http://gotolow.com/addons/low-events

Provides a wrapper for the channel-entries tag which allows you to do what you set out to do.

Solspace Date Field Filter: http://www.solspace.com/software/detail/date_field_filter/

This allows you to pick another field for date-based filtering. Different approach, for your ends same effect. This is $10 cheaper then Low's awesome module, and might be a better fit.

I'm sure there are ways to build this yourself with a custom plugin / whatever, but I'm more of a front-end kind of guy, plus: if you can fix this by spending 20 bucks and 5 minutes, to me that's always cheaper then spending an hour or two trying to work out how to fix this :). Hope this helps!

  • Steven
2
  • Ouch, totally forgot: I doubt you can keep using json:entries for this, but you can just use channel:entries and format your template as json. Depending on how strict the API is you can use HTTP Header to send the proper header :). – Steven Dec 3 '12 at 13:59
  • I've used Solspace Date Field Filter and it works great for this purpose. The only limitation I have run into so far with it is that it doesn't bring all of the default behaviour of the "regular" date field with it - for example, you can't use date headings. But using it as a limiter with a static or even dynamic start or end date on the loop works just fine. – Jean St-Amand Dec 3 '12 at 14:44
0

The docs have an example of setting the start_on parameter dynamically. Check here

Does require a bit of php though.

2
  • Erwin, I had a look at the stop_before but couldn't figure out how to use it with a custom field. – Brett Dec 3 '12 at 14:19
  • Ah sorry, hadn't noticed the custom field bit, in that case the answers above are solid options. – erwinheiser Dec 4 '12 at 14:38

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.