SSo, you said you need dynamic url to user bbpress profile. Correct?
This code will generate profile url
<?php echo bbp_get_user_profile_url( get_current_user_id() ); ?>
It should be easy to understand code and should work as you describe above.
Do not hesitate to contact me.
Here are my screenshots:
Home Page:
https://ibb.co/8m1225X
Single Page:
https://ibb.co/KhCDFtx
I would like the first forum topic created to be displayed on the post page.
You need to add another line of code to action function. We need to save topic id to post meta.
whole function.php
// Add the hook action
add_action('transition_post_status', 'send_new_post', 10, 3);
// Listen for publishing of a new post
function send_new_post($new_status, $old_status, $post) {
if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
$my_post = array(
'post_title' => $post->ID,
);
$forum_id = bbp_insert_forum($my_post);
$my_topic = array(
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'post_parent' => $forum_id
);
$topic_id = bbp_insert_topic($my_topic);
update_post_meta( $post->ID, 'forum_first_topic', $topic_id );
}
}
In single.php we can call your shortcode for showing topic by id because whe have post meta.
Paste this into loop:
$topic_id = get_post_meta( get_the_ID(), 'forum_first_topic', true );
echo do_shortcode(' [bbp-single-topic id='.$topic_id.']');
Whole single php loop:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="article">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<h2>Forum: <?php echo basename(get_permalink()); ?></h2>
<?php
$post = get_post(get_the_ID());
$mypost = get_page_by_title(get_the_ID(),OBJECT,'forum');
$topic_id = get_post_meta( get_the_ID(), 'forum_first_topic', true );
echo do_shortcode(' [bbp-single-topic id='.$topic_id.']');
echo do_shortcode( '[bbp-single-forum id='.$mypost->ID.']' ); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
How do I add the post content to the first post of the new topic?
Under this action:
add_action('transition_post_status', 'send_new_post', 10, 3);
Replace with updated function:
// Listen for publishing of a new post
function send_new_post($new_status, $old_status, $post) {
if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
$my_post = array(
'post_title' => $post->ID,
);
$forum_id = bbp_insert_forum($my_post);
$my_topic = array(
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'post_parent' => $forum_id
);
bbp_insert_topic($my_topic);
}
}
How do I append the post post title to the forum id?
Change this <h2>Forum: <?php echo get_the_ID(); ?></h2>
to this: <h2>Forum: <?php echo basename(get_permalink()); ?></h2>
That works great! Thank you so much.
How do I add the post content to the first post of the new topic? I can’t work out how to target the first post with add_action().
How do I append the post post title to the forum id? It looks like this (Forum: 67) it might be better if it was post-title-67 e.g starwars-67
I would like the first forum topic created to be displayed on the post page. I currently achieve this by:
Add new block
[/] shortcode
Add the bbpress shortcode
[bbp-single-topic id=40]
The id is found when edititing the topic in the address bar https://site/wp-admin/post.php?post=40&action=edit
Is there a way of automating this task?
the default is horizontal – do you you have a theme, plugin or code that is changing this?
The code is:
add_action ('template_redirect', 'forum_security');
function forum_security(){
$roles = wp_get_current_user()-> roles;
if(is_singular( array( 'forum', 'topic' ) )){
if(!is_user_logged_in()){
wp_redirect('/join');
exit;
}else{
if(current_user_can('administrator')){
return;
}elseif(!in_array('pmpro_role_1', $roles)){
wp_redirect('/product/channel-mcgilchrist');
exit;
}
}
}
}
I have written the below script to restrict users to access forums or topics. Here are the conditions:
1. If user in not logged in will be redirected to “Join” page.
2. If user is logged in but doesn’t have “pmpro_role_1” role, he will be redirected to “Product Page”.
3. If a user is the administrator, he can view the page.
The problem here is for topics in forum it is working except the latest created topic. And it is taking user to “Join” page even if the user is logged in and have the “pmpro_role_1”. What is happening here?
Please help.
add_action ('template_redirect', 'forum_security');
function forum_security(){
$roles = wp_get_current_user()-> roles;
if(is_singular( array( 'forum', 'topic' ) )){
if(!is_user_logged_in()){
wp_redirect('/join');
exit;
}else{
if(current_user_can('administrator')){
return;
}elseif(!in_array('pmpro_role_1', $roles)){
wp_redirect('/product/channel-mcgilchrist');
}
}
}
}
Yes, thank you a simple theme to demonstrate will be fine. I’m not too sure how to use hooks and I get very confused with how to use short codes and php together.
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
add_filter( 'bbp_new_topic_pre_content', 'rew_strip_tags' );
add_filter('bbp_edit_topic_pre_content', 'rew_strip_tags' );
add_filter( 'bbp_new_reply_pre_content', 'rew_strip_tags' );
add_filter('bbp_edit_reply_pre_content', 'rew_strip_tags' );
function rew_strip_tags ($content) {
$content = strip_tags($content);
return $content ;
}
Hi @egyptimhotep,
Yes please, could you provide code?
I wasn’t sure how to contact you on slack? There are a eight people with the handle @Jesse.
Thanks,
Slugs
I can help, you need to use hooks. If post is created, create a forum like post id of movie review. Then call shortcode with dynamic id of ppost form which is same as pos id of review.
If you need code, contact me.
<img src="img.jpg" style="float:left;">
Discuss with codex of WordPress. add_role function could help.
No code that can I put inside code snippet and insert shortcodes in functions.php?
Thank you!
Hello,
I want to ask about topic tags, is there any shortcode to display topic tags count? because when I put [bbp-topic-tags] shortcodes, the shortcodes only displaying name of topic tags and if topic tags popular, the topic tags name more larger.
I want to be like this:
topic tag1 (5)
topic tag2 (1)
topic tag3 (4)
and so on.
Is there any ideas?
Thank You.
You can go through this link for finding better solution.
Layout and functionality – Examples you can use
the last one is the telling one, looks like thismplugin is still active
C:\Users\Darren\Local Sites\elumine\app\public\wp-content\plugins\unyson\framework\extensions\shortcodes\extensions\page-builder\class-fw-extension-page-builder.php on line 510
Activating bbpress throws errors
All other plugins deactivated
bbpress v 2.65
wp v 5.5
https://elumine.interconnected.me/
theme – elumine, and twenty twenty, both up to date.
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘post_status’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2172
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘post_status’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2176
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘post_status’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2182
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘post_status’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2186
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2190
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘post_status’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2194
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2199
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2203
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-admin\includes\template.php on line 2208
[20-Aug-2020 08:10:54 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in C:\Users\Darren\Local Sites\elumine\app\public\wp-content\plugins\unyson\framework\extensions\shortcodes\extensions\page-builder\class-fw-extension-page-builder.php on line 510
Please advise.
Thanks.
could be down to a failure to close a <div>
contact me via
wilsonrobine@btinternet.com quoting this thread
Is there some way that the theme doesn’t realise the bbp code has finished so doesn’t realise it’s into the footer? Really clutching at straws here
I think that add-on is just for to enable you to more easily add bbp shortcodes rather than any sort of compatibility. I just don’t understand why, when it’s using the same template as other pages, it breaks the footer display..
hmmm….not sure what to suggest next
sort of looks like wp-bakery want you to buy an add-on for bbpress shortcodes
bbPress Shortcodes
and that page is a bakery page – ie a page where the shortcode is in a bakery item ?