'topic', 'posts_per_page' => 9, ]; if ( 'solved' === $data_forum ) { $args['meta_query'] = [ [ 'key' => '_bbp_topic_is_solved', 'value' => true, ], ]; } elseif ( 'unsolved' === $data_forum ) { $args['meta_query'] = [ [ 'key' => '_bbp_topic_is_solved', 'compare' => 'NOT EXISTS', ], ]; } elseif ( 'recent' === $data_forum ) { $args['order'] = 'DESC'; } elseif ( 'loved' === $data_forum ) { // Topics with positive vote counts (most loved) $args['meta_query'] = [ [ 'key' => 'bbpv-votes', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC', ], ]; $args['orderby'] = [ 'meta_value_num' => 'DESC', 'comment_count' => 'DESC', ]; } elseif ( 'unloved' === $data_forum ) { // Topics without positive votes (no votes or zero) $args['meta_query'] = [ 'relation' => 'OR', [ 'key' => 'bbpv-votes', 'compare' => 'NOT EXISTS', ], [ 'key' => 'bbpv-votes', 'value' => 0, 'compare' => '=', 'type' => 'NUMERIC', ], ]; } elseif ( 'popular' === $data_forum ) { $args['meta_query'] = [ 'relation' => 'OR', [ 'key' => '_btv_view_count', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC', ], [ 'key' => '_bbp_reply_count', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC', ], [ 'key' => 'bbpv-votes', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC', ], ]; $args['orderby'] = [ 'meta_value_num' => 'DESC', 'comment_count' => 'DESC', ]; } elseif ( 'featured' === $data_forum ) { $super_stickies = bbp_get_super_stickies(); // Get global super sticky topics // Get sticky topics from all forums $stickies = []; $forums = get_posts( [ 'post_type' => 'forum', 'posts_per_page' => -1, 'fields' => 'ids', ] ); foreach ( $forums as $forum_id ) { $stickies = array_merge( $stickies, bbp_get_stickies( $forum_id ) ); } // Merge both sticky types $sticky_topics = array_merge( $super_stickies, $stickies ); $sticky_topics = array_unique( $sticky_topics ); if ( ! empty( $sticky_topics ) ) { $args['post__in'] = $sticky_topics; } else { wp_send_json_error( __( 'No featured (sticky) topics found', 'forumax' ) ); } } // WP_Query arguments $forum_topics = new WP_Query( $args ); if ( $forum_topics->have_posts() ) { $i = 0; while ( $forum_topics->have_posts() ): $forum_topics->the_post(); $item_id = get_the_ID(); $author_id = get_post_field( 'post_author', $item_id ); $topic_id = $forum_topics->posts[ $i ]->ID; $vote_count = get_post_meta( $topic_id, "bbpv-votes", true ); $forum_id = bbp_get_topic_forum_id(); ?>