get( 'bbpc_ajax_search' ) ) {
return $search;
}
$like = '%' . $wpdb->esc_like( $keyword ) . '%';
return $wpdb->prepare(
" AND ( {$wpdb->posts}.post_title LIKE %s OR {$wpdb->posts}.post_content LIKE %s ) ",
$like,
$like
);
};
add_filter( 'posts_search', $bbpc_search_clause, 999, 2 );
// Main results query.
$results = new \WP_Query( array(
'post_type' => $query_post_types,
'post_status' => $query_post_status,
's' => $keyword,
'posts_per_page' => 10,
'bbpc_ajax_search' => true,
) );
remove_filter( 'posts_search', $bbpc_search_clause, 999 );
$results_count = $results->found_posts;
if ( $results_count > 0 ) {
$nsoresult = 'data-result=';
} else {
$nsoresult = 'data-noresult=';
}
?>
>
';
echo '';
if ( $results->have_posts() ) :
// Group results by post type.
$grouped = array();
while ( $results->have_posts() ) :
$results->the_post();
$type = get_post_type();
if ( ! isset( $grouped[ $type ] ) ) {
$grouped[ $type ] = array();
}
$grouped[ $type ][] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
'url' => get_the_permalink(),
'breadcrumb' => forumax_search_result_breadcrumb( get_the_ID(), $type ),
);
endwhile;
wp_reset_postdata();
// Render grouped results.
$type_labels = array(
'forum' => __( 'Forums', 'forumax' ),
'topic' => __( 'Topics', 'forumax' ),
'reply' => __( 'Replies', 'forumax' ),
'docs' => __( 'Documentation', 'forumax' ),
'post' => __( 'Posts', 'forumax' ),
);
// Document icon shared by every result row.
$result_icon = '
';
// Result type tabs (All / Forums / Topics / Replies), mirroring EazyDocs.
?>
$posts ) :
$tab_label = isset( $type_labels[ $type ] ) ? $type_labels[ $type ] : ucfirst( $type );
?>
$posts ) :
$label = isset( $type_labels[ $type ] ) ? $type_labels[ $type ] : ucfirst( $type );
?>
';
echo '
';
wp_die();
}
/**
* AJAX handler to fetch forums for Gutenberg block editor
* Used by the Single Forum block to populate the forum selector dropdown
*/
add_action( 'wp_ajax_bbpc_get_forums', 'forumax_get_forums_ajax' );
/**
* Get forums ajax.
*/
function forumax_get_forums_ajax() {
// Verify nonce for security
check_ajax_referer( 'forumax-nonce', 'nonce' );
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( 'Unauthorized' );
}
// Get all forums
$forums = new \WP_Query( [
'post_type' => 'forum',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
] );
$forum_list = [];
if ( $forums->have_posts() ) {
while ( $forums->have_posts() ) {
$forums->the_post();
$forum_list[] = [
'id' => get_the_ID(),
'title' => get_the_title(),
];
}
wp_reset_postdata();
}
wp_send_json_success( $forum_list );
}
/**
* Loading Post
*/
add_action( 'wp_ajax_forumax_loading_post', 'forumax_loading_post' );
add_action( 'wp_ajax_nopriv_forumax_loading_post', 'forumax_loading_post' );
/**
* Loading forum posts
*
* @return void
*/
function forumax_loading_post() {
// Check nonce
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) {
wp_die( '-1' );
}
$type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
$post_in = isset( $_POST['a_t_id'] ) ? sanitize_text_field( wp_unslash( $_POST['a_t_id'] ) ) : '';
$count = isset( $_POST['count'] ) ? sanitize_text_field( wp_unslash( $_POST['count'] ) ) : '';
$parent = isset( $_POST['parent'] ) ? sanitize_text_field( wp_unslash( $_POST['parent'] ) ) : '';
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$q = [
'post_type' => 'topic',
'post_parent' => $parent,
'order' => 'DESC',
'orderby' => 'post_date',
'post_status' => 'publish',
'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ),
'ignore_sticky_posts' => 1,
];
if ( 'author' === $type ) {
$auth_ids = [
'author' => $post_in,
];
$q = array_merge( $q, $auth_ids );
} elseif ( 'tag' === $type ) {
$tax_query[] = [
'taxonomy' => 'topic-tag',
'field' => 'term_id',
'terms' => $post_in,
];
}
$tax_query[] = [
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => [ 'post-format-quote', 'post-format-link' ],
'operator' => 'NOT IN',
];
if ( ! empty( $tax_query ) ) {
$tax_query = array_merge( [ 'relation' => 'AND' ], $tax_query );
$q = array_merge( $q, [ 'tax_query' => $tax_query ] );
}
$query = new WP_Query( $q );
if ( $query->have_posts() ) :
echo '