['forum', 'topic' ],
's' => $_POST['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( array(
'post_type' => ['forum', 'topic'],
's' => $_POST['keyword'] ?? '',
) );
$forum_count = $forum_query->found_posts;
if ( $forum_count > 0 ) {
$forum_nsoresult = 'data-result=';
} else {
$forum_nsoresult = 'data-noresult=';
}
?>
';
$forum = new WP_Query( array(
'post_type' => 'forum',
's' => $_POST['keyword'] ?? '',
'posts_per_page' => 5,
) );
if ( $forum->have_posts() ) :
echo '
' . esc_html__( 'Forums', 'forumax' ) . '
';
while ( $forum->have_posts() ) : $forum->the_post();
?>
'topic',
's' => $_POST['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 '
';
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' );
function forumax_search_data_forum() {
// Forums query
if ( class_exists( 'bbPress' ) ) :
echo '';
$forum = new WP_Query( array(
'post_type' => 'forum',
's' => $_POST['keyword'] ?? '',
'posts_per_page' => 5,
) );
if ( $forum->have_posts() ) :
echo '
' . esc_html__( 'Forums', 'forumax' ) . '
';
while ( $forum->have_posts() ) : $forum->the_post();
?>
'topic',
's' => $_POST['keyword'] ?? '',
'posts_per_page' => 5,
) );
if ( $topics->have_posts() ) :
echo '
' . esc_html__( 'Topics', 'forumax' ) . '
';
while ( $topics->have_posts() ) : $topics->the_post();
?>
';
endif;
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' );
add_action( 'wp_ajax_nopriv_bbpc_get_forums', 'forumax_get_forums_ajax' );
function forumax_get_forums_ajax() {
// Get all forums
$forums = new \WP_Query( array(
'post_type' => 'forum',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
) );
$forum_list = array();
if ( $forums->have_posts() ) {
while ( $forums->have_posts() ) {
$forums->the_post();
$forum_list[] = array(
'id' => get_the_ID(),
'title' => get_the_title(),
);
}
wp_reset_postdata();
}
wp_send_json_success( $forum_list );
}
/**
* Loading Post
*
* @return string
*/
add_action( 'wp_ajax_forumax_loading_post', 'forumax_loading_post' );
add_action( 'wp_ajax_nopriv_forumax_loading_post', 'forumax_loading_post' );
/**
* Loading forum posts
*/
function forumax_loading_post() {
global $wpdb;
$nonce = sanitize_text_field( $_POST['nonce'] );
$type = sanitize_text_field( $_POST['type'] );
$post_in = sanitize_text_field( $_POST['a_t_id'] );
$count = sanitize_text_field( $_POST['count'] );
$parent = sanitize_text_field( $_POST['parent'] );
if ( ! wp_verify_nonce( $nonce, 'forumax-nonce' ) ) {
die( '-1' );
}
$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' => - 1,
'ignore_sticky_posts' => 1,
];
if ( $type == 'author' ) {
$auth_ids = [
'author' => $post_in,
];
$q = array_merge( $q, $auth_ids );
} elseif ( $type == 'tag' ) {
$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 '