Skip to content

Instantly share code, notes, and snippets.

@illepic
Created March 30, 2011 06:51
Show Gist options
  • Save illepic/893974 to your computer and use it in GitHub Desktop.
Save illepic/893974 to your computer and use it in GitHub Desktop.
Get an arg from a path and turn that into NID args for views
<?php
//remember to remove the php beginning and end before pasting in views args
// get the third word from url (search/site/searchterm)
$searchterm = arg(2);
// new awesome node query system
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('title', $searchterm, 'CONTAINS')
->execute();
// load our nodes from the query
if ($entities) {
$nodes = entity_load('node', array_keys($entities['node']));
// array out our nids
foreach($nodes as $node){
$nids[]=$node->nid;
}
}
// return null instead of "all" in this particular case if there is no search
if ($nids) {
return implode('+',$nids);
} else{ return ''; }
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment