A posting to the Views PHP Filter documentation support issue by nfd; copied here as he wrote it, with one small edit made to fix a problem that cropped up in that comment thread Probably the nearly-canonical "simple use" of Views PHP Filter. Thanks again, nfd!
Posted by nfd on September 7, 2010 at 7:09am
Super Simple Example
Here is a good version of the script from #6 that essentually allows one to run a simple custom SQL query without node related retrieving variables involved.
$todaydayofweek = date('l'); // Any special variables should be first declared. In this case I am declaring the current day of week. Wash, rinse and repeat with as many variables as you need.
$nodeids = array(); // Creates the array that will be passed back to the filter.
$my_result = db_query("SELECT nid FROM node WHERE type LIKE 'ec_forecast_weather_data' AND title NOT LIKE '%$todaydayofweek%'"); // This is the query from the database. Place your custom SQL Query here between the set of quotation marks and brackets. Note how the custom variable is included in the SQL query.
while ($my_row = db_fetch_array($my_result)) // Adds the node ids to the array.
$nodeids = $my_row['nid'];
return $nodeids; // Passes the filter back
The function will pass a series of numbers separated by commas which will be added to the master SQL of the view you are working in. These numbers are the node id numbers.
It is important to NOT include the
tags. (It is this way throughout most of Drupal's front end.)
I only added this so as to further simplify the example in #6. I had a bit of trouble starting off understanding it so I've included my modifications to it here.