I'm using Drupal 7, Views and Flags to display nodes flagged by a user. I want to be able to hide the results, or use and alternate view display, if the view contains less than N number of results, Let's say 5.

So far I've tried using PHP code to validate my contextual filter:

Contextual filter: Flags:uid Specify validation code: PHP Code

if ($view->total_rows > 5) {
return TRUE;
} else {
  return FALSE;

Can anyone tell me where I'm going wrong here?

  • Try putting this logic in a template_preprocess_views_view() function, rather than in a contextual filter, per this question: drupal.stackexchange.com/questions/2321/… – schnippy Apr 14 '13 at 0:04
  • Is it not possible to do using PHP and contextual filters? I guess I would accept this as a definitive answer if that's the case. I'm still having trouble making sense of the linked-to answer, as I'm no closer to accomplishing my goal. – dgdoing Apr 16 '13 at 0:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.