Skip to:
Content
Pages
Categories
Search
Top
Bottom

bb-query help!

  • I’m trying to display a list of posts that are tagged with one tag but NOT another. For example, I want to display all posts tagged “FRUIT” but exclude posts tagged “Apples”.

    I tried creating a custom View, but this code does not work:

    function my_custom_views_init() {
    $args = array(
    'tag_id' => '35',
    'tag_id' => '!=72'
    );
    bb_register_view(
    'fruit-without-apples',
    'Fruit (excluding apples)',
    $args,
    false
    );
    }

    Neither does this code using bb-query directly:

    $topic_query = new BB_Query( 'topic',
    array(
    'tag_id' => '35',
    'tag_id' => '!=72'
    )
    );
    $results = $topic_query->results;

    foreach($results as $result) {
    echo $result->topic_title . '';
    }

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)

  • Gautam Gupta
    Moderator

    @gautamgupta

    You can only have one tag_id arg, that too should be an integer ( also = check is made, you can’t have != check ). Try this:

    function my_custom_views_init() {
    $args = array(
    'tag_id' => 35
    );
    bb_register_view(
    'fruits',
    'Fruit',
    $args,
    false
    );
    }

    You may try to short-circuit the query though, as shown in this plugin – http://plugins-dev.bbpress.org/browser/my-views/trunk/my-views-statistics.php


    Gautam Gupta
    Moderator

    @gautamgupta

    You can only have one tag_id arg, that too should be an integer ( also = check is made, you can’t have != check ). Try this:

    function my_custom_views_init() {
    $args = array(
    'tag_id' => 35
    );
    bb_register_view(
    'fruits',
    'Fruit',
    $args,
    false
    );
    }

    You may try to short-circuit the query though, as shown in this plugin – http://plugins-dev.bbpress.org/browser/my-views/trunk/my-views-statistics.php

    Thanks, Gautam, but that appears to just show all posts from Fruits (ie, not excluding Apples), unless I am missing something?

    For this particular application, I’m now trying to set it up so “Fruit” is a forum (so it has a forum id instead of a tag id), and using “Apple” tag to include/exclude certain posts. I’m hoping the bb_query in the bbp plugin will be more flexible.

    Thanks, Gautam, but that appears to just show all posts from Fruits (ie, not excluding Apples), unless I am missing something?

    For this particular application, I’m now trying to set it up so “Fruit” is a forum (so it has a forum id instead of a tag id), and using “Apple” tag to include/exclude certain posts. I’m hoping the bb_query in the bbp plugin will be more flexible.


    Gautam Gupta
    Moderator

    @gautamgupta

    In the plugin, it would make use of WP_Query which is a lot flexible – you would be able to do such things there afaik.


    Gautam Gupta
    Moderator

    @gautamgupta

    In the plugin, it would make use of WP_Query which is a lot flexible – you would be able to do such things there afaik.

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.