| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* All Search results |
| 5 |
*/ |
| 6 |
add_action( 'wp_ajax_bbpc_search_data_fetch', 'bbpc_search_data_fetch' ); |
| 7 |
add_action( 'wp_ajax_nopriv_bbpc_search_data_fetch', 'bbpc_search_data_fetch' ); |
| 8 |
function bbpc_search_data_fetch() { |
| 9 |
|
| 10 |
$opt = get_option( 'bbpc_opt' ); |
| 11 |
$is_ajax_search_tab = $opt['is_ajax_search_tab'] ?? ''; |
| 12 |
global $post; |
| 13 |
|
| 14 |
if ( class_exists( 'bbPress' ) ) { |
| 15 |
// All results query |
| 16 |
$all_results = new WP_Query( array( |
| 17 |
'post_type' => ['forum', 'topic' ], |
| 18 |
's' => $_POST['keyword'] ?? '', |
| 19 |
) ); |
| 20 |
$all_results_count = $all_results->found_posts; |
| 21 |
if ( $all_results_count > 0 ) { |
| 22 |
$all_nsoresult = 'data-result='; |
| 23 |
} else { |
| 24 |
$all_nsoresult = 'data-noresult='; |
| 25 |
} |
| 26 |
|
| 27 |
// Forum query |
| 28 |
$forum_query = new WP_Query( array( |
| 29 |
'post_type' => ['forum', 'topic'], |
| 30 |
's' => $_POST['keyword'] ?? '', |
| 31 |
) ); |
| 32 |
$forum_count = $forum_query->found_posts; |
| 33 |
if ( $forum_count > 0 ) { |
| 34 |
$forum_nsoresult = 'data-result='; |
| 35 |
} else { |
| 36 |
$forum_nsoresult = 'data-noresult='; |
| 37 |
} |
| 38 |
|
| 39 |
?> |
| 40 |
<div class="tab-item active all-active" <?php echo esc_attr( $all_nsoresult. 'No-Results-Found' ); ?>></div> |
| 41 |
<?php |
| 42 |
if ( class_exists( 'bbPress' ) ) : ?> |
| 43 |
<div id="search-forum" <?php echo esc_attr( $forum_nsoresult. 'No-Results-Found' ); ?> class="tab-item" ></div> |
| 44 |
<?php |
| 45 |
endif; |
| 46 |
} |
| 47 |
|
| 48 |
echo '<div class="bbpc-search-results-wrapper">'; |
| 49 |
|
| 50 |
// Forums query |
| 51 |
if ( class_exists( 'bbPress' ) ) : |
| 52 |
|
| 53 |
echo '<div class="search-results-tab forum show" id="search-forum-results">'; |
| 54 |
|
| 55 |
$forum = new WP_Query( array( |
| 56 |
'post_type' => 'forum', |
| 57 |
's' => $_POST['keyword'] ?? '', |
| 58 |
'posts_per_page' => 5, |
| 59 |
) ); |
| 60 |
|
| 61 |
if ( $forum->have_posts() ) : |
| 62 |
echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'bbp-core' ) . '</h2>'; |
| 63 |
while ( $forum->have_posts() ) : $forum->the_post(); |
| 64 |
?> |
| 65 |
<div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'"> |
| 66 |
<a href="<?php echo get_the_permalink(get_the_ID()); ?>"> |
| 67 |
<?php the_title(); ?> |
| 68 |
</a> |
| 69 |
</div> |
| 70 |
<?php |
| 71 |
endwhile; |
| 72 |
wp_reset_postdata(); |
| 73 |
endif; |
| 74 |
|
| 75 |
$topics = new WP_Query( array( |
| 76 |
'post_type' => 'topic', |
| 77 |
's' => $_POST['keyword'] ?? '', |
| 78 |
'posts_per_page' => 5, |
| 79 |
) ); |
| 80 |
|
| 81 |
if ( $topics->have_posts() ) : |
| 82 |
echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'bbp-core' ) . '</h2>'; |
| 83 |
while ( $topics->have_posts() ) : $topics->the_post(); |
| 84 |
?> |
| 85 |
<div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'"> |
| 86 |
<a href="<?php echo get_the_permalink(get_the_ID()); ?>"> |
| 87 |
<?php the_title(); ?> |
| 88 |
</a> |
| 89 |
</div> |
| 90 |
<?php |
| 91 |
endwhile; |
| 92 |
wp_reset_postdata(); |
| 93 |
endif; |
| 94 |
echo '</div>'; |
| 95 |
endif; |
| 96 |
|
| 97 |
echo '<h5 class="not-found-text">Not Found Result!</h5>'; |
| 98 |
echo '</div>'; |
| 99 |
die(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Forum Search results |
| 104 |
*/ |
| 105 |
add_action( 'wp_ajax_bbpc_search_data_forum', 'bbpc_search_data_forum' ); |
| 106 |
add_action( 'wp_ajax_nopriv_bbpc_search_data_forum', 'bbpc_search_data_forum' ); |
| 107 |
function bbpc_search_data_forum() { |
| 108 |
|
| 109 |
// Forums query |
| 110 |
if ( class_exists( 'bbPress' ) ) : |
| 111 |
|
| 112 |
echo '<div class="search-results-tab show" id="search-forum-results">'; |
| 113 |
|
| 114 |
$forum = new WP_Query( array( |
| 115 |
'post_type' => 'forum', |
| 116 |
's' => $_POST['keyword'] ?? '', |
| 117 |
'posts_per_page' => 5, |
| 118 |
) ); |
| 119 |
|
| 120 |
if ( $forum->have_posts() ) : |
| 121 |
echo '<h2 class="bbpc-search-title">' . esc_html__( 'Forums', 'bbp-core' ) . '</h2>'; |
| 122 |
while ( $forum->have_posts() ) : $forum->the_post(); |
| 123 |
?> |
| 124 |
<div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'"> |
| 125 |
<a href="<?php echo get_the_permalink(get_the_ID()); ?>"> |
| 126 |
<?php the_title(); ?> |
| 127 |
</a> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
endwhile; |
| 131 |
wp_reset_postdata(); |
| 132 |
endif; |
| 133 |
|
| 134 |
$topics = new WP_Query( array( |
| 135 |
'post_type' => 'topic', |
| 136 |
's' => $_POST['keyword'] ?? '', |
| 137 |
'posts_per_page' => 5, |
| 138 |
) ); |
| 139 |
|
| 140 |
if ( $topics->have_posts() ) : |
| 141 |
echo '<h2 class="bbpc-search-title">' . esc_html__( 'Topics', 'bbp-core' ) . '</h2>'; |
| 142 |
while ( $topics->have_posts() ) : $topics->the_post(); |
| 143 |
?> |
| 144 |
<div class="search-result-item forum" onclick="document.location='<?php echo get_the_permalink(get_the_ID()); ?>'"> |
| 145 |
<a href="<?php echo get_the_permalink(get_the_ID()); ?>"> |
| 146 |
<?php the_title(); ?> |
| 147 |
</a> |
| 148 |
</div> |
| 149 |
<?php |
| 150 |
endwhile; |
| 151 |
wp_reset_postdata(); |
| 152 |
endif; |
| 153 |
echo '</div>'; |
| 154 |
endif; |
| 155 |
die(); |
| 156 |
} |