I was curious if anyone has or knows of any function or shortcode that I can use that pulls the first topic from a specific forum and shows it on a page?
@robin-w , does your bbpress shortcode plugin do this?
I basically want to create a section on my homepage called “Announcements” and have the latest two topics from my forums with the Title and an excerpt from the post body included.
and couldn’t use it in bbPress function’ file.
Put this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
Code Snippets
sorry for late reply.
You would do better to link to topic and reply content
so
add_filter( 'bbp_get_reply_content', 'content_link_for_user_snippets',80, 2 );
add_filter( 'bbp_get_topic_content', 'content_link_for_user_snippets', 80, 2 );
I’d run them at priority 80, as bbpress runs various actions at this point, including one called ‘bbp_make_clickable’ at priority 60, which would probably reverse your efforts !
ytParticipant
Hello
I want a code to use in the function file of bbPress to hide all links in the content of forum’s topics and replies for visitors.
I mean until a visitor is not logged in the forum, instead of displaying links, it shows a text message like “displaying links to members only” and a registration link to register and enter his account so that redirects to the last page in the topic or reply.
Additional Explanation:
I Use the code below:
add_filter( 'the_content', 'content_link_for_user_snippets', 1 );
function content_link_for_user_snippets( $content = '' ) {
// Snippets.ir
if( ! is_user_logged_in() ) {
preg_match_all( "#<a(.*?)>(.*?)#i", $content, $matches );
$num = count( $matches[0] );
for( $i = 0; $i < $num; $i++ ) {
$content = str_replace( $matches[0][ $i ], '<a href="' . ( get_permalink() ) . '"><span style="color:#F00;">[displaying links to members only]<span></a>', $content );
}
}
return $content;
}
in My site’s Theme and word very nice but it doesn’t have any effect in form and couldn’t use it in bbPress function’ file.
You are asking someone to write code in their free time to do something that their code wasn’t intended to do.
it’s that simple
this is what I might out in style pack
add_action ('bbp_template_before_single_forum' , 'bsp_template_notices') ;
add_action ('bbp_template_before_single_topic' , 'bsp_template_notices') ;
function bsp_template_notices() {
// Bail if no notices or errors
if ( ! bbp_has_errors() ) {
return;
}
// Define local variable(s)
$errors = $messages = array();
// Get bbPress
$bbp = bbpress();
// Loop through notices
foreach ( $bbp->errors->get_error_codes() as $code ) {
// Get notice severity
$severity = $bbp->errors->get_error_data( $code );
// Loop through notices and separate errors from messages
foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
if ( 'message' === $severity ) {
$messages[] = $error;
} else {
$errors[] = $error;
}
}
}
// Display errors first...
if ( ! empty( $errors ) ) : ?>
<div class="bbp-template-notice error" role="alert" tabindex="-1">
<ul>
<li>
<?php echo implode( "</li>\n<li>", $errors ); ?>
<a href="#new-post">
<?php _e('Click here to correct', 'bbp-style-pack') ; ?>
</a>
</li>
</ul>
</div>
<?php endif;
}
I’ve found that annoying in the past, and not bothered to think about correcting.
This basic code will display the errors at the top, but I might look to improve on that in style pack
add_action ('bbp_template_before_single_forum' , 'bbp_template_notices') ;
add_action ('bbp_template_before_single_topic' , 'bbp_template_notices') ;
Put this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
Code Snippets
Perfect. Thx Robin!!
The following now works
/* only run forum script in forum area */
add_action( 'wp_print_scripts' , 'deregister_forum_script');
function deregister_forum_script(){
if ( !is_bbpress() ){
wp_deregister_script('forum-js');
}}
This ticket is now closed. thx!
I have this now, but how do i assigm $kat_id to tthe Blog post category when i submit my Blogpost?
function add_content_before_first_reply_content($content,$id){
$post = get_post($id);
$topic_id = bbp_get_topic_id();
$reply_id = bbp_get_reply_id();
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
$kat_id = wp_get_post_parent_id($post);
$content_to_add ="<a href="create-new-post?vis=$kat_id> Add new blog </a>
if ($topic_id === $reply_id) {
// do whatever you need to in here
$content .= $content_to_add;
}
return $content;
}
add_filter( 'bbp_get_reply_content', '
// Only add onclick if replies are threaded
if ( bbp_thread_replies() ) {
// Array of classes to pass to moveForm
$move_form = array(
$r['add_below'] . '-' . $reply->ID,
$reply->ID,
$r['respond_id'],
$reply->post_parent
);
i think it somewhere here
so what are you using to login – bbpress login widgets, shortcodes or what?
vBulletin
I found this guide there is no written how to do it …
always pays to check how someone did something 🙂
the code that is being called at that point just loads the worpdress access details, so that loaded from wordpress.
I’d suggest a chat with your host provider to see if they know anything in their set up that might have cached an old version.
Oh I found the error in my code above
Just replacing
is_category()
with
is_archive()
Still, not sure I’m taking the best approach here,
maybe I’m missing a simpler way to categorise topics?
Actually, it was not fixed.
Many other users have reported the same issue now.
What is weird that some users can log in normally, but for some it throws that same error page.
{"success":false,"data":[{"code":"bbp_converter_db_connection_failed","message":"Database connection failed."}]}
Hi there,
I’m looking for a general advice if I’m hading in the right direction how to allow users to categorise their topics and replies? I’m making progess but having trouble to display those topics in the term archives, display the terms in the forum posts, etc.
In building in custom taxonomies should I be building on top of the existing topic tags, making them hierarchical –
Or taking the approach of registering two new taxonomies –
- ‘region’ eg ‘Australia, New Zealand, Tasmania’
- ‘issue’ eg ‘homelessness, rough sleeping, couchsurfing
I’ve then added a term picker to the new topic form –
But I’m stuck getting topics/replies to display on the the term archives,
this doesn’t seem to work to eg to display topic on this archive
https://www.forum.backtofrontdesign.co/region/victoria/
am i using the correct post type slugs?
function add_post_types_to_archives( $query ) {
// We do not want unintended consequences.
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( is_category() && empty( $query->query_vars['suppress_filters'] ) ) {
// Add more slugs with the other CPTs.
$post_types = array( 'topic');
$query->set(
'post_type',
array_merge(
array( 'post' ),
$post_types
)
);
}
}
I’ll keep persevering to display the terms on forum archives and single topics, but any advice or assistance from the community would be so much appreciated to get this campaign up and running.
Forums
A project for https://www.oldertenants.org.au/
I take it you have an add action statement
add_action( 'bbp_register_views' ....
View Topic By
I’m creating my own custom forum view using the register_views code. The function works but for some reason the url isn’t working. What am I missing?
function my_custom_register_views() {
// Latest Replies Custom View
bbp_register_view(
'latest-replies',
__( 'Latest Replies', 'my_custom_register_views' ),
apply_filters( 'bbp_register_view_latest_replies', array(
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_key' => '_bbp_last_active_time',
'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()),
'post_type' => bbp_get_topic_post_type(),
'show_stickies' => false
)
) );
}
always learning – I’ve never considered that a plugin would stop caching to mobiles 🙂
Basically it is extra code to not cache mobiles – you have to find out what the http request is coming from and then stop the default cached request. you need to have a list of mobiles to work this out.
Normally you would only do this if your mobile site needed different output, rather than not be cached!
So seems that your plugin is really just a shop door to a paid product.
I’ve always used w3 total cache, but then it was the first one I picked many years ago, and it seems to work fine, so I just keep using it.
it does have the ability to turn off mobile caching, use a different theme, or redirect to a different site.
that still doesn’t tell, me how you are doing the online bit.
so you must be using some code/stuff at that point to show this. so what widget or code are you using ?
Hello, I use a widget bbpress that allow the option to display “members online” but I can’t separate the normal members and the admin members
Can I use shortcodes or a custom html to insert that options on my homepage? using elementor builder?
I fixed it 🙂 . Sorry, there was no problem with your code, or the code from the developer of the theme, there was a problem with a other plugin. I use the WordFence Security plugin, which also saves the last login metadata, but in a I different place, so I have deleted the first part of the snippet (which is saving the last login metadata) and changed
$last_login = get_user_meta($user_id, ‘last_login’, true);
to
$last_login = get_user_meta( $user_id, ‘wfls-last-login’, true);
So thanks for the help, looks like the problem is solved.
so bbpress does not do this bit, so what plugin or code are you using to display this area?
that’s basically a rewrite of my code, so suggest that you have a problem somewhere.
You are putting this code in your functions file – yes ?
in which case can you show the actual code including the function/lines before it and after it