Hello,
Any ideas? Maybe something like this?
<?php echo bbp_get_forum_id(bbp_get_topic_id()); ?>
Thanks.
Is there anyway I can get a list of topic IDs inside a forum ID?
sorry missed this first time round.
you’ll want bbp_has_topics which you’ll find in
\includes\topics\template.php
line 140
function bbp_has_topics( $args = '' )
you can call it with a forum id eg
<?php $query = bbp_has_topics( array( 'post_parent' => '2579') ); ?>
this will return an array of topics from forum ID 2579 which you can then work with
Hello @robin-w,
I still need to get this straight. Maybe something like this would work?
/*Remove all topics from Amazon CloudSearch if topic is in a private forum*/
/*Private Forums are added as an integration through a plugin*/
/*Amazon CloudSearch is added as integration through a plugin*/
function exclude_topics_in_private_forum() {
$forum_id = bbp_get_forum_id();
$query = bbp_has_topics( array( 'post_parent' => $forum_id) );
foreach($query as $q) {
if(is_private_forum($forum_id) ) {
update_post_meta($q, 'exclude', 1);
} elseif(!is_private_forum($forum_id) ) {
delete_post_meta($q, 'exclude');
}
}
}
add_action('bbp_new_forum', 'exclude_topics_in_private_forum' );
add_action('bbp_edit_forum', 'exclude_topics_in_private_forum' );
It is important to note that I am using custom plugins to pull off a lot of the private forum abilities that way I can control user access better. I think the code snippet above will do it. Thoughts?
Thanks.
You could try bbp_get_all_child_ids()
, though it does a direct database query, and has no limit on the results that get returned, so in cases where there are many topics to chug through, it can be a bit much.
Hello,
Okay, I like something that doesn’t query the DB to much. Would something like this work? I’m somewhat new to arrays and post_meta, but trying to learn fast.
/*Remove all topics from Amazon CloudSearch if topic is in a private forum*/
/*Private Forums are added as an integration through a plugin*/
/*Amazon CloudSearch is added as integration through a plugin*/
function exclude_topics_in_private_forum() {
$forum_id = bbp_get_forum_id();
$query = bbp_get_all_child_ids($forum_id, 'post');
foreach($query as $q) {
OR
foreach($query as $key => $q) {
if(is_private_forum($forum_id) ) {
update_post_meta($q, 'exclude', 1);
OR
update_post_meta($key, 'exclude', 1);
} elseif(!is_private_forum($forum_id) ) {
delete_post_meta($q, 'exclude');
}
}
}
add_action('bbp_new_forum', 'exclude_topics_in_private_forum' );
add_action('bbp_edit_forum', 'exclude_topics_in_private_forum' );
How does that look? Any suggestions?
Thanks.
Suggest you try them and see.
looks like you are learning fast.
Looking back on it now, I never did have the development time to make this work before I discontinued CloudSearch, but this looks to be the best code if anyone’s brave enough to try it in the future. 🙂
function exclude_topics_in_private_forum() {
$forum_id = bbp_get_forum_id();
$query = bbp_get_all_child_ids($forum_id, 'post');
foreach($query as $key => $q) {
if(is_private_forum($forum_id) ) {
update_post_meta($key, 'exclude', 1);
} elseif(!is_private_forum($forum_id) ) {
delete_post_meta($q, 'exclude');
}
}
}
add_action('bbp_new_forum', 'exclude_topics_in_private_forum' );
add_action('bbp_edit_forum', 'exclude_topics_in_private_forum' );
Thanks for the help.
It is working perfectly, except that you need to specify the good post type (here it is ‘topic’).
$query = bbp_get_all_child_ids($forum_id, 'topic');