I have an exposed data filter with only the year granularity. If a user selects a particular year in the exposed filter, I would like to display that year in the title or header. For example is a user selects the year 2009, I would like to use "2009" as part of the header of that page.

I'm not sure I understand how arguments work for exposed filters. It appears as thought they are not the same as regular drupal arguments.

Looking at the url of the exposed filter I guessed at the following. Don't know if i'm even remotely close.

<?php
$new_var = $view-> date_filter[value][year];
print $new_var;
?>

Any ideas?

Thank you for any help.

CommentFileSizeAuthor
#27 error.JPG87.35 KBchrisdomingo
#20 exposed-filter-array.png30.01 KBscott859

Comments

akolahi’s picture

I forgot to mention I'm exposing filter to block

dawehner’s picture

I think the following code could work

<?php
$view = views_get_current_view();
dsm($view->exposed_input);
?>
akolahi’s picture

Thank you.

For some reason that was giving me a white screen error. instead i tried the below and got the word 'Array' outputted.

<?php
$view = views_get_current_view();
$new_var = $view->exposed_input;
print $new_var;
?>
dagmar’s picture

To use dsm() you need the devel module.

akolahi’s picture

That's a beautiful thing!! Many thanks!!

<?php
$view = views_get_current_view();
print $view->exposed_input[date_filter][value][year]; 
?>
akolahi’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sapark’s picture

Thanks! Also works with a select list of node-referenced years as a Views argument.

Add year argument,
Add %1 as title to use when argument is present,
Provide default argument,
Default argument type: PHP code

return $view->exposed_input[field_list_year_nid];
twistedindustries’s picture

<?php
$view = views_get_current_view();
print $view->exposed_input[date_filter][value][year];
?>

Can someone be more specific with this code, I have tried every combination and cannot get it to work. Maybe a generic sample of this could would help.

twistedindustries’s picture

Status: Closed (fixed) » Needs review

Changing status

dagmar’s picture

Status: Needs review » Active

Descriptions of the Priority and Status values can be found in the Issue queue handbook.

dawehner’s picture

@twistedindustries

I does not help you if you post the think to different issues. People helping here are just mans, so they might wait to answer your question if you put the same more then one time.

shushu’s picture

Since useful for my needs, I guess it can be for others.
Here is a small module that do it nicely, with themeing enabled.
http://drupal.org/project/exposed_filter_data

Comments are welcome

bfr’s picture

@9 Use print_r to find out what data your array contains:

<?php
$view = views_get_current_view();
print_r($view->exposed_input);
?>
cancerian7’s picture

Many Thanks.

dagmar’s picture

Status: Active » Fixed

Ok, I think this is already fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joetsuihk’s picture

remember to check_plain($view->exposed_input[date_filter][value][year]);

scott859’s picture

StatusFileSize
new30.01 KB

Greetings,

I'm having a similar issue. I have a view that has a number of exposed filters and I wish to list what filter criteria is being used in the header.

Using the following code in the header:

$view = views_get_current_view();
print_r($view->exposed_input);

I get a print out of the data in the array (see attached screenshot).

My issue is that the first field, labeled "Location Code" is a node reference, and as you can see from the screen-shot the array is listing the value of the selected item(s) rather than the label (the title of the node).

If anyone can give any insight into printing the label (or title) of the node reference item(s) selected, rather than the value, I would appreciate it.

Thank you,

Scott

joetsuihk’s picture

re #20

try

<?php
//field_hotel_group is the field name
$mappings = optionwidgets_options(content_fields('field_hotel_group'));
?>

my blog post about this: http://joetsuihk.com/%E6%9F%A5%E6%89%BE%E4%B8%80%E5%80%8B%E9%81%B8%E5%96...

scott859’s picture

@joetsuihk

Thanks so much, that was a big help.

Thanks again,

Scott

ayalon’s picture

Here is an example that also works with Views 3:

$view = views_get_current_view();
if($view->exposed_input[field_date_value][value][year]) {
  return $view->exposed_input[field_date_value][value][year];
}
else {
  return 'all';
}
tribe_of_dan’s picture

This post took me ages to find and helped me greatly. Thanks! :)

Anonymous’s picture

Would #23 work in Drupal 7?

Is this handled any differently?

The module provided hasn't been ported yet.

Thanks,

Drew

TimelessDomain’s picture

chrisdomingo’s picture

StatusFileSize
new87.35 KB

hello guys..

i used this snippet:

<?php
$view = views_get_current_view();
print $view->exposed_input[date_filter][value][year];
?>

it worked on my view, however it displays error messages.

any info about this is greatly appreciated! ^^

bfr’s picture

You need to use quotes(' or ") when your array keys are strings:

$view = views_get_current_view();
print $view->exposed_input['date_filter']['value']['year'];

For more help, please paste your whole code, the error is speaking of "line 6" and you are showing only two lines.

chrisdomingo’s picture

thank you bfr. It worked. i thought that the value passed on the filter is still an integer, never thought of it as string... :)

TravisJohnston’s picture

+1

vvs’s picture

I use data from GET for display as title:

/**
 * THEME_PREPROCESS_VIEWS_VIEW
 * @param type $vars
 * 
 */
function MYTHEME_preprocess_views_view(&$vars) {
  if ($vars['view']->name == 'viewName') {
    // get var from GET
    $obj_type = $_GET['obj_type'];
    if (isset($obj_type)) {
      // obj_type is the taxonomy term, get taxonomy term name
      $tax_name=taxonomy_term_load($obj_type)->name;
      // if taxonomy term have parents
      $tax_parent = taxonomy_get_parents_all($obj_type);
      if (isset($tax_parent[1])) {
        // add parent name to taxonomy term name
        $tax_name =  $tax_parent[1]->name . ', ' . $tax_name;
      }
      //update title
      $vars['view']->build_info['title'] = $tax_name;
    }
}
museumboy’s picture

Issue summary: View changes

Ok, I'm putting this out there because it worked for me. I added this code to the header of my block view.

$view = views_get_current_view();

if(isset($view->exposed_input['field_release_date_value']['value']['year'])) {
  echo "<h2>Press Releases for ", $view->exposed_input['field_release_date_value']['value']['year']; "</h2>";
}
else {
  echo  "<h2>Press Releases for ", date("Y"); "</h2>";
}

the field name that you are sorting is defined in the Better Exposed Filter settings (if you're using that). I kept trying field_release_date and that wasn't working. I needed to use field_release_date_value. I'm not getting any errors with this code.

terracoders’s picture

I'm not really a PHP kinda guy, but I'm also throwing this out there for anyone who finds it useful. I needed to get custom text in the view header based on taxonomy term from which the view filters results. Like Museumboy above, I pulled the field name from Better Exposed Filters (term_node_tid_depth) and used it to get taxonomy term ID. Based on the term ID (numerical value) I put together a custom header. The code might be a little redundant (again, PHP not my strength), but it was an easy fix for custom headers. You would, of course, need to adjust the numerical TID values to match your own use case.


$view = views_get_current_view();

if(isset($view->exposed_input['term_node_tid_depth']) && $view->exposed_input['term_node_tid_depth'] == 1616) {
  echo "<div class=\"resultshead\"><h2>Some Custom Text for Term 1</h2></div>";
}

else if(isset($view->exposed_input['term_node_tid_depth']) && $view->exposed_input['term_node_tid_depth'] == 1606) {
  echo "<div class=\"resultshead\"><h2>Some Custom Text for Term 2</h2></div>";
}

else if(isset($view->exposed_input['term_node_tid_depth']) && $view->exposed_input['term_node_tid_depth'] == 1611) {
  echo "<div class=\"resultshead\"><h2>Some Custom Text for Term 3</h2></div>";
}

else if(isset($view->exposed_input['term_node_tid_depth']) && $view->exposed_input['term_node_tid_depth'] == 1621) {
  echo "<div class=\"resultshead\"><h2>Some Custom Text for Term 4</h2></div>";
}

else if(isset($view->exposed_input['term_node_tid_depth']) && $view->exposed_input['term_node_tid_depth'] == 1626) {
  echo "<div class=\"resultshead\"><h2>Some Custom Text for Term 5</h2></div>";
}