I try to return the node under the term id, and limit to 2 only. I tried this code with specified term id "642" which works

$args = '642';
$nids = array();
$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = %d LIMIT 2", $args);
while ($row = db_fetch_array($myquery)) {
  $nids[] = $row['nid'];
}
return $nids;

However when I tried to pass the URL argument to this filter, as shown below.

$args = arg(2);
$nids = array();
$myquery = db_query("SELECT nid FROM {term_node} WHERE tid = %d LIMIT 2", $args);
while ($row = db_fetch_array($myquery)) {
  $nids[] = $row['nid'];
}
return $nids;

It does not work. Is this some functional limitation of this module. Can anybody advise if there is any other workaround. Thanks.

Comments

noemed7’s picture

Same problem here, I've created a function that uses a parameter, I use this function in Node: PHP filter as it follows:

return my_function(arg1);

The url is node/222 and the function gets a 0 instead of 2222.

Please how can I solve this.

Thanks in advance

Arkrep’s picture

Component: Miscellaneous » Code

This worked for me ...

<?php
$view = views_get_current_view();
$args = $view->args;
$vars = $args[1]; 
$nodeids = array();
$my_result = db_query("SELECT nid FROM {content_field} WHERE field_value < %d", $vars);
$nodeids[1] = -1;
while ($my_row = db_fetch_array($my_result)){
	$nodeids[] = $my_row['nid'];
}
return $nodeids;
?>
gnassar’s picture

Category: bug » support
Priority: Major » Normal
Status: Active » Closed (works as designed)

The arg() function has never been available within a view. Has nothing to do with Views PHP Filter. See Views issue #388024: Arguments from path not available to Views?!.

You can try setting up arguments in your view and using %1, et al., as is suggested in that link.

Otherwise, you can pull the arguments from $view->args like Steven Wilson did above.

Steven: you may want to try that %1 approach -- I don't actually know that it'll work this early in the loader process, but if it does it'll save you that expensive view load in the first line. Let me know if that works for you.

Makku01’s picture

did this work out? are there any experiences with this approach in php-filter?