Hello,

I need a view that lists nodes of two content types (A and B). But I also want to limit B to certain taxonomy terms. So if I add a taxonomy term filter, it would filter out all nodes of content type A. Is there a way to only filter taxonomy types against content type B?

I can probably figure it out if I know where to start, but for now this is pretty unclear to me.

Thanks in advance,
Danny

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Danny_Joris’s picture

To be clear: I want all these fields in the same view, as I need to randomize them all.

merlinofchaos’s picture

Status: Active » Fixed

I don't think there is a way to do this with Views because of the way taxonomy terms work. You need an OR, which isn't really supported by Views 2 at all, and taxonomy terms don't play nicely with the Views OR module. It might be possible in Views 3 with the OR conditions.

Anonymous’s picture

Status: Fixed » Active

Argh you got me wanting to know the answer now after our IRC chat!

Found this:

http://sethsandler.com/software/drupal-6-creating-activity-stream-views-...

(discovered here http://drupal.org/node/726252#comment-2994594)

Danny_Joris’s picture

FileSize
42.96 KB

I've been told that hook_views_query_alter might work so I added this in a custom module:

<?php
//provides a views hook.
function custom_views_query_alter(&$view, &$query) {

  if($view->name == 'headerslider'){
  	
	print dsm($query);
  	
  	
  }
}
?>

See attachment.
Only local images are allowed.
Would it be possible to add a second array to the "where" array? I also wouldn't know how to fill out the %s replacement patterns...

Danny_Joris’s picture

Wow, you guys are fast :) Tnx

dawehner’s picture

@Danny

Does the link at #3 helps you to solve the issue, so this can be set to "fixed"?

Danny_Joris’s picture

FileSize
53.76 KB

I'm trying to use #3 - for now without success.

I have this for my custom_views.module.
For now it only outputs the twitter feed nodes. I also need the news_item titles.

<?php
<?php 
// $Id: custom_views.module,v 1.272.2.1 2009/04/27 12:25:24 goba Exp $

function custom_views_views_pre_execute(&$view) {

if($view->name=="feed_block")
    {
     $view->build_info['query']= 
	"
    SELECT node_data_field_twitter_id.field_twitter_id_value AS node_data_field_twitter_id_field_twitter_id_value,
    node_data_field_twitter_id.field_twitter_body_value AS node_data_field_twitter_id_field_twitter_body_value
 	FROM node node 
 	LEFT JOIN content_type_twitter node_data_field_twitter_id ON node.vid = node_data_field_twitter_id.vid
 	WHERE (node.status <> 0) AND (node.type in ('twitter'))

	UNION

	SELECT node.nid AS nid,
    node.title AS node_title
 	FROM node node 
 	INNER JOIN term_node term_node ON node.vid = term_node.vid
 	WHERE (node.status <> 0) AND (node.type in ('news_item')) AND (term_node.tid IN (1, 288, 0, 0, 0))
	";
    //count_query determines the pager.  Do this so the right item count is returned. If you don't do this, you'll only return the query amount
   	$view->build_info['count_query']=$view->build_info['query'];
   
 }  
}

/**
* This module is Views 2.0 enabled.
* Implementation of hook_views_api().
*/
function custom_views_views_api() {
  return array('api' => 2.0);
} 

?> 

Views settings screenshot in attachment.

Danny_Joris’s picture

Status: Active » Closed (won't fix)

I've been juggling around with the field settings and the Union Query order for quite a while now, and I must come to the conclusion that it probably is not going to solve my issue. The output is just too messed up.

Thanks for your feedback, everybody! I appreciate it.

Danny_Joris’s picture

FileSize
63.93 KB

Ah, and in #4 I accidentally added a wrong screenshot. This is the correct one.

So it's not possible to add a second array to "where" , right?