Hi All,

I think I am misunderstanding some of the views module functionality ;)

I created a custom content type using CCK with just 2 fields: end_date and news_text. The idea is to create a block view that will display all news_text if today <= end_date.

Using a view, I am trying to use a filter to add the "WHERE CLAUSE" to the SQL statement, something similar to "WHERE now() <= end_date". The problem I am having first of all is:

1.) Is this the right way to accomplish this?

2.) When trying to choose the filed end_date to filter, the Content group only has the news_text field available to add the filter to. Why does it not list Content: end_date?

3.) Is it possible to create an index on the end_date column in the table?

Any insights will be greatly appreciated.

Thanks!
Kosie

Comments

kosie99’s picture

Another question on views:

4.) I have no access restrictions on the view or on the block. The content is published, but it only displays in the block for authenticated users, even though I don have any of "anonymous" or "authenticated" users ticked in the access control list.

Anybody have any ideas what I am doing wrong here?

mdupont’s picture

Have you enabled the content permissions submodule? If so, you must allow anonymous user to see end_date and news_text fields. By default they can't, so the view is empty.

mdupont’s picture

We are using something similar on our website, and we created the view with the help of the Date module: http://drupal.org/project/date
It will allow you to create a filter on a date field and to compare this date to the current date (or any other date). It's perfect if you want to hide news items after some time, but keep them published. If you don't need to archive news, use the Scheduler module instead, which will automatically unpublish a node on a specified date.

kosie99’s picture

Thanks for that.

I actually have the Date module installed, but now it seems that filtering cannot be done on fields of type Date. I recreated the content type using a normal Text type for the end_date and that shows up perfectly in Views filtering.

Is there something I need to configure in Views or Date modules to enable filtering on Dates or do I just have to live with using a text field? Just realised that the operators in Views filters does not include "greater than", "less than", etc.

Looks like the Scheduler is the way to go, or I will just have to code the SQL statement myself (if that is possible in Views)

mdupont’s picture

First, check your permissions (that may be why Date fields aren't appearing). Make sure that the field "end_date" is of one of date types (I'm using "Datestamp", maybe "Date" and "Datetime" don't play well with Views). Then when editing your view you should have a filter called "Date : Date (node)" which have several parameters, including "greater than"' "less than", "current date", etc.

bhp’s picture

When you're trying to add a views filter on a date field that you added to your CCK object, and you're scrolling through the list of fields to add as filters, don't look for your date field in the content area, but look instead for something listed as "Date: Date (node)". In the configuration for this filter option, there will be a list of date fields - this is where you choose your own date field.