CCK example

A very thorough example by alan.pinkert.

LowMemory's original example

LowMemory's verbatim original example for Views PHP Filter, to my knowledge the first such example for 6.x in the handbook. I owe LowMemory thanks for officially kicking off this section.

nfd's "Super Simple Example"

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

Views PHP Filter examples

Views PHP Filter is a powerful way to customize your Views result set -- but it can be a little difficult to jump into at first. Users have generously donated the following examples so that others can get a general idea of how it works and figure out how to adapt the filter for their purposes. Feel free to throw in more examples by creating a child page -- the more the merrier!

The "official" text on how Views PHP Filter works, from its README:

Subscribe with RSS Subscribe to RSS - viewsphpfilter