Created
March 30, 2011 06:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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