I have a content type of "Class" that has a date field attached to it field_class_date.

When a node of the type "Class" is viewed, I would like to display links to other classes that are on the same day of that particular class.

I tried doing this with views, but couldn't quite figure it out.

2 Answers 2


To solve this, (1) I placed code in node--class.tpl.php which retrieved the current class date

$date = entity_metadata_wrapper('node', $node)->field_class_date->value->value();

Then, (2) I modified that value to get the start of the day and the end of the day ($start and $end) in the following format: Y-m-d H:i:s

(3) Perform a query using EFQ to grab a list of the nodes that share the same date:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'class')
  ->fieldCondition('field_class_date', 'value', array($start, $end), 'BETWEEN')
  ->fieldOrderBy('field_class_date', 'value', 'ASC');
$result = $query->execute();

(4) Loop through each result and create the content I want to display later in node--class.tpl.php

foreach($result['node'] as $i) {
  $node = node_load($i->nid);
  $date = entity_metadata_wrapper('node', $node)->field_class_date->value->value();
  $name = entity_metadata_wrapper('node', $instructor)->field_class_instructor->value();
  // Build a string of output that I want to display later in the $content array
  $classes_today = etc...

(5) Finally, I added the $classes_today string to the $content array:

$content['more_classes']['#prefix'] = '<h2 class="classes-on-this-day">Classes on this Day:</h2><div class="more-classes">';
$content['more_classes']['#markup'] = $more_classes;
$content['more_classes']['#weight'] = '4';
$content['more_classes']['#suffix'] = '</div>';

Hi for this you can simply place a filter for date field in your view.

Choose your date field and add to filters.

Select Operator as " Is equal to" and then type "NOW" in the selection for filtering.

This should filter down your class content as per present/current date.

  • I don't want to filter classes to "NOW." I want to filter them to the date of the class node being viewed, which is specified by field_class_date, which is attached to all classes.
    – carsonw
    Apr 6, 2014 at 14:15
  • oh all right... Apr 6, 2014 at 21:08

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.