0

I have created an ajax view that displays the contents of a group. It shows one page at a time, with a nice jquery pageturn effect when you go to the next page.

I now want to insert the actual group node at the start of this view. I can't put it in header or template files, as then it wont work with the ajax pagination.

I have worked out the SQL I need to get the results I want... SELECT node.nid AS nid FROM d7_node node LEFT JOIN d7_og_membership og_membership_node ON node.nid = og_membership_node.etid AND og_membership_node.entity_type = 'node' WHERE (( (node.status = '1') AND (og_membership_node.gid = '42' ) )) OR (node.nid = '294') ORDER ASC

The SQL my view is currently using is... SELECT node.nid AS nid FROM d7_node node LEFT JOIN d7_og_membership og_membership_node ON node.nid = og_membership_node.etid AND og_membership_node.entity_type = 'node' WHERE (( (node.status = '1') AND (og_membership_node.gid = '42' ) )) ORDER ASC

So basically I just need to tag on 'OR (node.nid = '294')' to the WHERE.

I'm trying to use this custom module

function hook_views_views_query_alter(&$view, &$query) {
if ($view->name == 'flipbook_ii') {
    $nid = $view->args['0'];
    $query->where[] = array(
      'conditions' => array(
        '0' => array(
          'field' => 'node.nid',
          'value' => $nid,
          'operator' => '=',
        ),
      ),
      'type' => 'OR',
    );
  }
}

But that is still setting the WHERE query WHERE (( (node.status = '1') AND (og_membership_node.gid = '42' ) AND (node.nid = '294') ))

Can anyone explain a way that works?

1 Answer 1

0

Took me a while but eventually solved this....

Needed to add

$query->group_operator = 'OR';

into my hook_views_query_alter.

1
  • Cool that you got it working :) Please accept this as the answer, so the question gets removed from the unanswered queue.
    – Letharion
    May 20, 2012 at 9:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.