0

So, I have a view which filters content from 3 different content types: Books, photos and articles and outputs in the same view.

All three content types have an independent "issue number" field. The view basically filters content based on the issue number. Now in order to create views for each issue, I was individually creating views for each issue. In order to pull content from multiple content types, the OR operator in the filter menu came in handy. The OR relationship is as follows (Let's take Issue 5.1 as an example) in the second group:

  1. Content published = yes AND 2.Content type is one of Article,books,photos

AND

  1. field_books_issue_number = 5.1 OR
  2. field_photos_issue_number = 5.1 OR
  3. field_articles_issue_number = 5.1

Now, this works perfectly fine, with the only downside that I had to create a view for each issue.

Now, I want to pass the issue number as a URL argument, so that I don't have to create a view for each issue. It would rather be a wildcard path such as: /issue/% and the wildcard value would take the value from the URL (using contextual filter). To do this, I changed the filters to:

  1. Content published = yes AND 2.Content type is one of Article,books,photos

AND

  1. field_books_issue_number = Not empty OR
  2. field_photos_issue_number = Not empty OR
  3. field_articles_issue_number = Not empty

and added the following contextual filter:

  1. field_books_issue_number = Value from URL
  2. field_photos_issue_number = Value from URL
  3. field_articles_issue_number = Value from URL

But as we know, contextual filters have a default AND relationship, which means that only the first condition will satisfy, since the other 2 fields in the contextual filter are from different content types and the other two conditions will automatically fail for every content being filtered.

Now, my question is this: 1. Can different content types share a common field? 2. If not, can the normal filter take values from the URL? 3. If not, can we add an OR operator to the contextual filters? 4. If not, is there an easier way to do what I'm trying to do without having to create an individual view for each issue?

Hope the question is clear. Thanks in advance.

Kaushik

1 Answer 1

0

Can different content types share a common field?

In drupal 7 (maybe also in drupal 6) yes you can. When you add a new field to your content type, you've the possibility to add a field that already exist: "Add existing field".

Then filtering on the field should work for any content type using it.

Basically, I would add to the three content types Books, Photos and Article the same field "field_issue_number".

I think that will make your life easier :)

1
  • Wow, didn't think of this at all! But works, thanks :)
    – KaushikTD
    Commented Dec 26, 2013 at 15:22

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.