| @@ -480,14 +480,18 @@ | ||
| 480 | 480 | // Currently inside a search loop |
| 481 | 481 | } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) { |
| 482 | 482 | $bbp_topic_id = $bbp->search_query->post->ID; |
| 483 | 483 | |
| 484 | - // Currently viewing/editing a topic, likely alone | |
| 485 | - } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && ! empty( $bbp->current_topic_id ) ) { | |
| 484 | + // Topic ID already set by a shortcode / theme-compat render | |
| 485 | + } elseif ( ! empty( $bbp->current_topic_id ) ) { | |
| 486 | 486 | $bbp_topic_id = $bbp->current_topic_id; |
| 487 | 487 | |
| 488 | 488 | // Currently viewing/editing a topic, likely in a loop |
| 489 | 489 | } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) { |
| 490 | + $bbp_topic_id = $wp_query->post->ID; | |
| 491 | + | |
| 492 | + // Main query is a topic even if single-topic flags are not set yet | |
| 493 | + } elseif ( isset( $wp_query->post->post_type ) && ( bbp_get_topic_post_type() === $wp_query->post->post_type ) ) { | |
| 490 | 494 | $bbp_topic_id = $wp_query->post->ID; |
| 491 | 495 | |
| 492 | 496 | // Currently viewing/editing a reply |
| 493 | 497 | } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) { |