Pair view fields content on a Drupal 7 view quick howto

Valid for: Drupal 7, Views 3.

I have two multiple text fields on a Drupal 7 content type.

multiple fields

I want to display those fields paired by delta in a view. Here the code I used in my module named mymodule.module.

function mymodule_views_pre_render(&$view) {
  // pair field contents
  if ($view->name == 'my_view_name' && $view->current_display == 'my_view_display') {
    foreach ($view->result as $key => $res) {
      if ($res->field_data_field_youtube_url_delta != $res->field_data_field_youtube_url_description_delta) {

Thanks to hook_views_pre_render().

I use this piece of code to pair Youtube URLs and plain text description  for a JSON output generated via Views Datasource.

Remember to disallow multiple values when adding these fields to your view or you’ll get incoherent results.

Customize exposed filter on Drupal View

Tested on:

  • Drupal 5.x
  • Views 1.6

When you have to filter a view by a content type, you have to use Exposed filters. Since default list is somewhat ugly (a select with some elements and CTRL to be pressed) we transform it in simple checkboxes.

Copy and paste this code into your template.php:

# I use imagecache because on my site is active
# and doesn't use hook_form_alter
/** Display checkboxes instead select for exposed views filters */
function imagecache_form_alter($form_id, &$form) {
  if($form_id == 'views_filters' && arg(0) == 'change_to_your_view_path_before_slash') {
    if(!empty($form)) {
      foreach ($form as $id => $field) {
        if ($form[$id]['#type'] == 'select' && $form[$id]['#multiple'] == 'multiple') {
          # from select to checkboxes
          $form[$id]['#type'] = 'checkboxes';
	  foreach($form[$id]['#options'] as $key=>&$content) {
            # hide from list all content types that aren't mycontenttype or mycontenttype2
            if($key!='mycontenttype' && $key!='mycontenttype2'){

To hide operators dropdown, you have to check “lock operators” on views page.

See also:

Set views title dynamically for blocks and pages

Tested on: Drupal 5.x – Views 1.6

Problem: you want to display a taxonomy term name as view title, for block and themes.

Solution: On views edit screen, just add to your Argument > Argument handling code:

$args[0] = 3;

Where 3 is the Term ID you want to display as name. When term name will be updated, view title will be updated too.

You haven’t to add other arguments via GUI, just this code.