[ 'forum', 'topic' ], 's' => $keyword, ] ); $all_results_count = $all_results->found_posts; if ( $all_results_count > 0 ) { $all_nsoresult = 'data-result='; } else { $all_nsoresult = 'data-noresult='; } // Forum query $forum_query = new WP_Query( [ 'post_type' => [ 'forum', 'topic' ], 's' => $keyword, ] ); $forum_count = $forum_query->found_posts; if ( $forum_count > 0 ) { $forum_nsoresult = 'data-result='; } else { $forum_nsoresult = 'data-noresult='; } ?>
>
class="tab-item" >
'; // Forums query if ( class_exists( 'bbPress' ) ) : echo '
'; $forum = new WP_Query( [ 'post_type' => 'forum', 's' => $keyword, 'posts_per_page' => 5, ] ); if ( $forum->have_posts() ) : echo '

' . esc_html__( 'Forums', 'forumax' ) . '

'; while ( $forum->have_posts() ) : $forum->the_post(); ?>
'topic', 's' => $keyword, 'posts_per_page' => 5, ] ); if ( $topics->have_posts() ) : echo '

' . esc_html__( 'Topics', 'forumax' ) . '

'; while ( $topics->have_posts() ) : $topics->the_post(); ?>
'; endif; echo '
' . esc_html__( 'Not Found Result!', 'forumax' ) . '
'; echo '
'; wp_die(); } /** * Forum Search results */ add_action( 'wp_ajax_forumax_search_data_forum', 'forumax_search_data_forum' ); add_action( 'wp_ajax_nopriv_forumax_search_data_forum', 'forumax_search_data_forum' ); /** * Search data forum. */ function forumax_search_data_forum() { // Check nonce check_ajax_referer( 'forumax-nonce', 'nonce' ); // Sanitize keyword $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field( $_POST['keyword'] ) : ''; // Forums query if ( class_exists( 'bbPress' ) ) : echo '
'; $forum = new WP_Query( [ 'post_type' => 'forum', 's' => $keyword, 'posts_per_page' => 5, ] ); if ( $forum->have_posts() ) : echo '

' . esc_html__( 'Forums', 'forumax' ) . '

'; while ( $forum->have_posts() ) : $forum->the_post(); ?>
'topic', 's' => $keyword, 'posts_per_page' => 5, ] ); if ( $topics->have_posts() ) : echo '

' . esc_html__( 'Topics', 'forumax' ) . '

'; while ( $topics->have_posts() ) : $topics->the_post(); ?>
'; endif; 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 '
'; while ( $query->have_posts() ) : $query->the_post(); global $post; $author_id = $post->post_author; $parent_post_id = $parent; $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; ?>
get_the_ID(), 'type' => 'avatar', 'size' => 40, ] ); ?>

', esc_url( get_permalink() ) ), '

' ); ?>
'; else : echo '
'; echo '
'; echo ''; echo '

' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '

'; echo '

' . esc_html__( 'You could search again.', 'forumax' ) . '

'; echo '
'; echo '
'; endif; wp_die(); } /** * Filter posts by status (open/closed) * * @return void */ add_action( 'wp_ajax_forumax_open_post', 'forumax_open_post' ); add_action( 'wp_ajax_nopriv_forumax_open_post', 'forumax_open_post' ); /** * Open post. */ function forumax_open_post() { // Check nonce if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) { wp_die( '-1' ); } $is_queried_obj = is_singular( 'forum' ) ? get_queried_object_id() : false; $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'] ) ) : ''; $userid = isset( $_POST['userid'] ) ? sanitize_text_field( wp_unslash( $_POST['userid'] ) ) : ''; $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $q = [ 'post_type' => 'topic', 'post_parent' => $parent, 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), 'ignore_sticky_posts' => 1, 'author' => $userid, ]; if ( 'open' === $type ) { $status = [ 'post_status' => 'publish', ]; $q = array_merge( $q, $status ); } elseif ( 'closed' === $type ) { $status = [ 'post_status' => 'closed', ]; $q = array_merge( $q, $status ); } $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 '
'; while ( $query->have_posts() ) : $query->the_post(); global $post; $author_id = $post->post_author; //$parent_post_id = get_post_meta( get_the_ID(), '_bbp_topic_id', true ); $parent_post_id = $parent; $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; ?>
get_the_ID(), 'type' => 'avatar', 'size' => 40, ] ); ?>

', get_permalink() ), '

' ); ?>
'; else : echo '
'; echo '
'; echo ''; echo '

' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '

'; echo '

' . esc_html__( 'You could search again.', 'forumax' ) . '

'; echo '
'; echo '
'; endif; wp_die(); } /** * Sort posts * * @return void */ add_action( 'wp_ajax_forumax_loading_sort_post', 'forumax_loading_sort_post' ); add_action( 'wp_ajax_nopriv_forumax_loading_sort_post', 'forumax_loading_sort_post' ); /** * Loading sort post. */ function forumax_loading_sort_post() { // Check nonce if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'forumax-nonce' ) ) { wp_die( '-1' ); } $sort = isset( $_POST['sort'] ) ? sanitize_text_field( wp_unslash( $_POST['sort'] ) ) : ''; $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, 'post_status' => 'publish', 'posts_per_page' => get_option( '_bbp_topics_per_page', 10 ), 'ignore_sticky_posts' => 1, ]; if ( 'newest_posts' === $sort ) { $newest_posts = [ 'order' => 'DESC', ]; $q = array_merge( $q, $newest_posts ); } elseif ( 'oldest_posts' === $sort ) { $oldest_posts = [ 'order' => 'ASC', ]; $q = array_merge( $q, $oldest_posts ); } elseif ( 'comment_count' === $sort ) { $comment_count = [ 'meta_key' => '_bbp_reply_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', ]; $q = array_merge( $q, $comment_count ); } elseif ( 'comment_date' === $sort ) { $comment_count = [ 'meta_key' => '_bbp_reply_count', 'meta_type' => 'NUMERIC', 'orderby' => 'meta_value_num', 'order' => 'ASC', ]; $q = array_merge( $q, $comment_count ); } elseif ( 'recent_updated_post' === $sort ) { $post_date = [ 'orderby' => 'post_modified', 'order' => 'DESC', ]; $q = array_merge( $q, $post_date ); } elseif ( 'last_recent_updated_post' === $sort ) { $post_modified = [ 'orderby' => 'post_modified', 'order' => 'ASC', ]; $q = array_merge( $q, $post_modified ); } $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 '
'; while ( $query->have_posts() ) : $query->the_post(); global $post; $author_id = $post->post_author; $parent_post_id = $parent; $favoriters = get_post_meta( get_the_ID(), '_bbp_favorite', true ); $favorite_count = ! empty( $favoriters ) ? $favoriters[0] : '0'; $get_reply = get_post_meta( get_the_ID(), '_bbp_reply_count', true ); $_reply_count = isset( $get_reply ) && ! empty( $get_reply ) ? $get_reply : 0; ?>
get_the_ID(), 'type' => 'avatar', 'size' => 40, ] ); ?>

', esc_url( get_permalink() ) ), '

' ); ?>
'; else : echo '
'; echo '
'; echo ''; echo '

' . esc_html__( 'Oops! No results matched your search.', 'forumax' ) . '

'; echo '

' . esc_html__( 'You could search again.', 'forumax' ) . '

'; echo '
'; echo '
'; endif; wp_die(); }