I've got a block view set up to get the latest 3 blog posts by term. I'm using Term ID with depth as the argument and providing the default arg using php code with return arg(1); as the arg.

Works fine in views preview with arguments entered, but on an actual page it returns nothing. Never had a problem with this before in 6.x. Is there something new I'm completely missing? I've read through docs and tried a few different ways to return the default arg, but no luck.

The view is attached. Any help would be greatly appreciated.

CommentFileSizeAuthor
view.txt7.63 KBjseltzer

Comments

wizonesolutions’s picture

Have you printed (e.g. with dsm) arg(1) to make sure it's what you expect? I'm surprised it works while editing the view. Normally I have the opposite issue, although I haven't used Views 7 much and as such probably aren't qualified to comment. But thought I'd take a stab :)

jseltzer’s picture

Yeah, I tried changing the argument code to account for pathauto aliasing (even though the aliases worked before in preview.

So I changed the term id argument code to

$path = drupal_get_path_alias($_GET['q']); 
$path = explode('/', $path); 
if($path[0] == 'laws' ||$ path[0] == 'issues' || $path[0] == 'culprits' || $path[0] == 'themes' :
return $path[1];
endif;

Using dpm on $path[1] gives me the term alias and I assumed that the Argument validator for Taxonomy Terms, which is set to "Term Name converted to Term ID", would get me the ID, but maybe not?

jseltzer’s picture

Status: Active » Closed (fixed)

Added a return ''; to the default argument if the statement was false and that did the trick. Not entirely sure why though.

doompal’s picture

Perhaps because your code is expected to return a value in every case?