Info
- 5 posts
- 3 voices
- Started 1 year ago by nikeshoes2a
- Latest reply from alexchenco
- This topic is not resolved
bb-query help!
-
- Posted 1 year ago #
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?
-
- Posted 1 year ago #
You can only have one
tag_idarg, 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
-
- Posted 1 year ago #
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.
-
- Posted 1 year ago #
In the plugin, it would make use of
WP_Querywhich is a lot flexible - you would be able to do such things there afaik. -
- Posted 1 year ago #
-
You must log in to post.