Compatible with BBPress
-
Hello @lando1982,
Is this plugin compatible with the default BBPress search? If so, how can I get it working?
Thanks, still a great plugin!
-
Hi Alex,
never tried before.. probably you need to sync BBPress data into the CS index but unfortunately I don’t know how BBPress works.. I’m sorry…
Hello,
Okay, I’ll give it a try.
Thanks.
I have bbPress installed and the plugin is working well. I followed Andreas instructions for configuration and choose the questions and answers custom post types that are associated with our bbPress forum. They indexed fine and are searchable. The only hiccup is that the search result display the terms ‘topic’ and ‘replies’ instead of our custom ‘question’ and ‘answer’ but we should be able to easily solve for that with a bit of custom styling.
Yes, you have 2 ways… the easier one is to provide a custom CSS/JS on your site that rename at runtime the labels, the complex solution can be to create a “content-search.php” custom “Content box type” (change “Frontpage settings”) and in your custom PHP file customize the result box as you want..
Hello @lando1982,
One thing that is happening is I am using another plugin that sets private topics and replies. Anyway to adjust the search to not include those based on conditional?
Thanks.
Hi Alex, if those items are not too much you can use the exclude post/page feature, isn’t it?
Hello, that will not work. I need to exclude all topics and replies that are private. Anyway I can do that? Can I add a conditional in a file?
if(is_private_topic($topic_id) )
if (is_private_reply($reply_id) )
Thanks.
You can add the “exclude” custom field programmatically when you save the topic/reply? like an action on:
add_action('transition_post_status', 'manage_post_manage_transition', 10, 3);
Hello @lando1982
Alright, I’m confused. I’m not sure if this will end up going in post_meta table or somewhere else. I’ve never tried to include a custom field for a bbPress topic. I think I will need more than just that action above though. Can you offer anymore guidance?
So far, I know this will probably be needed and this is what I think will do it.
function create_field() { // grab topic id $topic_id = bbp_get_topic_id(); // used to check if field exists or not $exclude_post_field = get_post_meta($topic_id, 'acs_exclude', '1', true); // if field does not exist, if it private topic if(is_private_topic($topic_id) && !$exclude_post_field) ) { // if so, add the value $exclude_field = add_post_meta($topic_id, 'acs_exclude', '1', true ); // if topic is no longer private, check to make sure field exists } else if(!is_private_topic($topic_id) && $exclude_post_field) ) { // Finally, delete the field $exclude_field = delete_post_meta($topic_id, 'acs_exclude', '1'); } else { // If normal topic, empty variable $exclude_field = ''; } // return the value return $exclude_field; } // hook in to topic/edit form for saving add_action('bbp_new_topic', 'create_field', 10, 1); add_action('bbp_edit_topic', 'create_field', 10, 1);
I got the idea from this: https://bbpress.org/forums/topic/bbpress-and-custom-fields/#post-163149
Thoughts?
Thanks.
Hi Alex,
looking the bbPress documentation your code can be simplified with this one:
function create_field($topic_id) { if (is_private_topic($topic_id)) { // if is private topic, add the 'acs_exclude' value (the fourth paramameter set to true makes add/update depending if value already exists) $exclude_field = add_post_meta($topic_id, 'acs_exclude', 1, true); } else { // If normal topic, delete the field delete_post_meta($topic_id, 'acs_exclude'); } // return no values } add_action('bbp_new_topic', 'create_field', 10, 1); add_action('bbp_edit_topic', 'create_field', 10, 1);
Can you try?
Hello @lando1982
I’m having trouble understanding. If you delete the field for normal topic but the field doesn’t exist, isn’t that kind of bad to try to remove something that doesn’t exist in the first place? Not saying yours is wrong, I’m just trying to understand the logic behind it. I did modify my code to look like this.
function create_field() { // grab topic id $topic_id = bbp_get_topic_id(); // used to check if field exists or not $exclude_post_field = get_post_meta($topic_id, 'acs_exclude', '1', true); // if field does not exist, if it private topic if(is_private_topic($topic_id) && !$exclude_post_field) ) { // if so, add the value $exclude_field = add_post_meta($topic_id, 'acs_exclude', '1', true ); // if topic is no longer private, check to make sure field exists } else if(!is_private_topic($topic_id) && $exclude_post_field) ) { // Finally, delete the field $exclude_field = delete_post_meta($topic_id, 'acs_exclude'); } else { // If normal topic, empty variable $exclude_field = ''; } // return the value return $exclude_field; } // hook in to topic/edit form for saving add_action('bbp_new_topic', 'create_field', 10, 1); add_action('bbp_edit_topic', 'create_field', 10, 1);
Awaiting feedback. Thanks.
Ok Alex, but check if field exists can be unnecessary.. if exist will be deleted, instead no operation needs for WP, just return true if field is deleted or false if not exists..
I think it’s not important to check if exists before (also for add_post_meta)..But, if you try your code, does it works?
PS:
$exclude_post_field = get_post_meta($topic_id, 'acs_exclude', '1', true);
should be:
$exclude_post_field = get_post_meta($topic_id, 'acs_exclude', true);
$exclude_field = add_post_meta($topic_id, 'acs_exclude', '1', true );
should be:
$exclude_field = add_post_meta($topic_id, 'acs_exclude', 1, true );
Finally, I think it’s better in the “if” clause if you check “$exclude_post_field != 1” not “!$exclude_post_field”.. you have to try.. I’m not sure..
Hello,
I’ve come up with the final version of the code here. I think the goal is to not make so many DB queries. I will also have to adapt the function further to remove locked topics and internal forums.
/*Exclude private topics from search results*/ function exclude_private_topics_search() { // grab topic id $topic_id = bbp_get_topic_id(); // used to check if field exists or not $private_topic_field = get_post_meta($topic_id, 'acs_exclude', true); // if field does not exist, if it private topic if(is_private_topic($topic_id) && !$private_topic_field) ) { // if so, add the value $private_topic_field = add_post_meta($topic_id, 'acs_exclude', 1, true ); // if topic is no longer private, check to make sure field exists } else if(!is_private_topic($topic_id) && $private_topic_field) ) { // Finally, delete the field $private_topic_field = delete_post_meta($topic_id, 'acs_exclude'); } else { // If normal topic, empty variable $private_topic_field = ''; } // return the value return $private_topic_field; } // hook in to topic/edit form for saving add_action('bbp_new_topic', 'exclude_private_topics_search', 10, 1); add_action('bbp_edit_topic', 'exclude_private_topics_search', 10, 1);
Plan on testing for sure later then I will post results. Until then, try at your own risk.
Thanks.
Ok Alex, let me know
Hello @lando1982,
This code would be the one to do it.
/*Exclude private topics from search results*/ function exclude_private_topics_search() { $topic_id = bbp_get_topic_id(); if(gdbbx_is_topic_private($topic_id) ) { add_post_meta($topic_id, 'acs_exclude', 1, true ); } else { delete_post_meta($topic_id, 'acs_exclude'); } } add_action('bbp_new_topic', 'exclude_private_topics_search' ); add_action('bbp_edit_topic', 'exclude_private_topics_search' );
I think I will write a function along the same lines to exclude private forums. Any ideas as to what hooks I could use for that? It will be a back end update to make a forum private.
Thanks.
- The topic ‘Compatible with BBPress’ is closed to new replies.