Support » Plugin: Ads by datafeedr.com » Only Show Ads That Are In Two Specific Groups

  • I understand the plugin does not have this feature, instead it shows any ads that are in any one of the specified groups..

    I want to extend or modify the plugin so that it will only show ads that are in all of the selected groups.

    Example:
    Ad 1 is in Group A & Group C
    Ad 2 is in Group B & Group C
    Ad 3 is in Group A & Group D
    Ad 4 is in Group B & Group D

    With just these four groups, assume there are many more ads that are in two or more of the groups..

    Right now, if I choose to show ads from Group A & Group C, then Ad 1, Ad 2 and Ad 3 are displayed.

    I want to only display Ad 1, since it is the only ad (of the four) that is in both groups.

    What do I need to do to accomplish this?

    I have looked at the taxonomy query and the query as a whole, unfortunately my sql skills are not enough to figure this one out. I see that it searches for ads with any term “IN” the selected groups, but I do not know how I can change it to return ads that contain all the terms.

    http://wordpress.org/extend/plugins/ads-by-datafeedrcom/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author datafeedr

    (@datafeedrcom)

    Haven’t tested it but I think you need to change this code:

    $ids = implode( ",", $group_ids );
    		$sql['JOIN'] = " LEFT JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy AS tax ON (tr.term_taxonomy_id = tax.term_taxonomy_id) ";
    		$sql['AND'] = " AND tax.taxonomy = 'dfads_group' AND tax.term_id IN($ids) ";
    		return $sql;

    To something like this:

    $sql['JOIN'] = " LEFT JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy AS tax ON (tr.term_taxonomy_id = tax.term_taxonomy_id) ";
    		$sql['AND'] = " AND tax.taxonomy = 'dfads_group' ";
    		foreach ($group_ids as $id) {
    			$sql['AND'] .= " AND tax.term_id = $id ";
    		}
    		return $sql;

    Like I said, haven’t tested it but it might get you closer to what you want.

    Thread Starter Chris

    (@web2guru)

    Thanks, I had the same idea and tried that. It returned no results. I’m going to do some more testing to see what the query returns normally, or maybe I got something wrong. I will review this later today.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Only Show Ads That Are In Two Specific Groups’ is closed to new replies.