Single reply redirect to topic
-
Hi!
How to redirect single reply in result search to topic thread?
-
@angelorocha Not sure exactly what you are trying to achieve here so could you please describe it a bit more in detail by sharing screenshot or page URL of it?
Hi Vinod.
In search results, when the result is a “reply” post type, the link show only a reply.
I want click in the reply and this redirect to parent topic. Sorry for my bad english, i’m from Brazil =)Actually you have to click on the topic title as shown in the screenshot here http://imgur.com/a/T5aNz to go to the topic where the reply is posted.
Hi, Vinod Dalvi. Sorry for delay.
Actually, when click in link for single reply in search results, the single reply don’t show the parent topic in single reply template, i want redirect single reply template to topic parent.
I’d like to know the answer to this question too.
@angelorocha, did you ever find a solution?Same problem here. I’m looking for a way to redirect the reply post (for me it’s listed via a widget) to the topic where the reply was created. Currently it redirects to another page showing only the reply post, not to the topic page where the reply was originally created. Any suggestions?
No solution for this problem yet =(
OK, still trying to figure this one out…
From what I can tell, the problem we are encountering is that the URL is defined as:
https://site.com/forums/reply/12345
when it needs to be:
https://site.com/forums/topic/[topic_title]/#post-12345
In the first case, the redirect goes to the single reply post. In the second, the redirect goes to the post within the topic thread, which is what I believe we are each trying to achieve here.
Also, it seems to work correctly in the bbpress Recent Replies widget — meaning the widget utilizes the URL in the second case (above) and redirects correctly to the parent forum/topic. I’ve looked through the widgets.php file but can’t figure out where it’s pulling the reply_url from and why it’s different from the reply post permalink.
Does anyone know where the permalinks or URLs for the reply custom post type are defined in the bbpress plugin files? Perhaps that could be a place to start…
And, any suggestions or assistance would be appreciated!
bbpress with a default theme (eg twentseventeen) will do the following
- search for say ‘hello’
- bbpress will produce all single topics and single replies that match this (which could be many)
- for a reply you will see the reply with the words In reply to :the topic name as a link
- click the topic name and you are taken to the topic
If this is not what you are getting, then come back
You can also go directly to the reply by clicking the post #number on the top right of each result.
Are you wanting to change your search results so that “In reply to: Topic Title” redirects to the #post within that topic?Thanks, @robin-w & @brent0r, for your responses.
Using search, I get exactly as @robin-w describes, which makes sense and is not a problem (for me, at least). The problem I am encountering is that third-party themes and plugins that use the bbpress reply post type redirect to the single reply post as opposed to the post in the topic thread. That is, they go to the reply/number ULR instead of the topic_title/#post-number URL. I’m aware, as @brent0r suggests, that clicking on the post #number in the top right takes the user to the topic_title/#post-number, but unfortunately this isn’t intuitive for my users and it is negatively impacting engagement in my community.
I notice that the bbpress Recent Replies widget redirects users to /#post-number, which is what I am trying to accomplish. I just can’t seem to figure out where that slug is defined, as it is apparently not the same as the bbpress reply post type. I’m assuming I could modify the plugin’s files to behave similarly if I could figure out where to tell it to pull the ULR from.
I wonder, too, if perhaps I should have started a separate thread. I thought the issue I had was the same as @angelorocha, the OP, but perhaps we’re encountering different problems…? My apologies if I’ve hijacked the thread with a different issue. I’m hoping the solution(s) will be the same…
Thanks again for your help. I appreciate this community.
@kdelsimone
If you want the link changed from the topic to the reply, I suggest copying loop-search-reply.php from /wp-content/plugins/bbpress/templates/default/bbpress to your child themes bbpress directory @ /wp-content/themes/theme-child/bbpress
From there you can edit it and change line 25 from this:
<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink( bbp_get_reply_topic_id() ); ?>"><?php bbp_topic_title( bbp_get_reply_topic_id() ); ?></a></h3>
to this:
<a class="bbp-topic-permalink" href="<?php bbp_reply_url(); ?>"><?php bbp_topic_title( bbp_get_reply_topic_id() ); ?></a></h3>
I coded something you can add to your functions.php file which will do this.
// ---------------------------------------- REDIRECT REPLY POSTS TO TOPIC WITH REPLY ANCHOR function jrevillini_reply_redirect( $wp_query ) { if ( !function_exists('bbp_get_reply_url') ) return; if ( !isset($wp_query->query['reply']) ) return; wp_safe_redirect( bbp_get_reply_url( $wp_query->query['reply'] ) ); } add_action('pre_get_posts', 'jrevillini_reply_redirect');
BONUS: smooth scroll to the anchor point when page loads with this plugin: https://wordpress.org/plugins/page-scroll-to-id/
@jrevillini Bless you!! This is exactly what I was looking for, and the BONUS smooth scroll is a bonus indeed–Thank you!!!
@jrevillini So here’s something curious: I dropped the code into a bp-custom.php file and it works great. However now users can’t edit their posts. When they click EDIT on a post, they’re simply redirected back to the post and not the /edit page. When I remove the code, the redirect to the /edit page works. Have you observed the same?
Oops! You are right. I created a gist for it and updated with the fix: https://gist.github.com/jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514
Thanks for pointing that out. If you notice any other issues, please let me know.
@jrevillini Perfect! Thanks again!!
where this code to input? https://gist.github.com/jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514
i already put this script in my functions.php but my blog error …
@kdelsimone can you tell me how to solved it?
Please.
Yes, you could add it to functions.php, but it may be easier for you to install the plugin Code Snippets and then paste it into a snippet like so: http://tinyurl.com/y49p67as
@blogxkomo I created a custom.php file and dropped the code in there. Works like a charm. You could also try creating a custom plugin or using @jrevillini ‘s solution above.
My solution:
In your “head.php” before <html> tag:
do_action('wpss_before_head');
In your function.php:
function wpss_single_reply_redirect() { global $wp; $get_request = explode( '/', $wp->request ); $reply_id = end( $get_request ); if ( in_array( 'reply', $get_request ) ): if ( in_array( 'edit', $get_request ) ): return; endif; wp_redirect( bbp_get_reply_url( $reply_id ), 301 ); exit; endif; }
Sorry!
In your “functions.php” add this line:add_action( 'wpss_before_head', 'wpss_single_reply_redirect' );
=)
- You must be logged in to reply to this topic.