<?php global $post; $question = QA_Questions::convert($post); $et_post_date = et_the_time(strtotime($question->post_date)); $category = !empty($question->question_category[0]) ? $question->question_category[0]->name : __('No Category', ET_DOMAIN); $category_link = !empty($question->question_category[0]) ? get_term_link($question->question_category[0]->term_id, 'question_category') : '#'; ?> <li <?php post_class('question-item pending-question'); ?> data-id="<?php echo $post->ID; ?> "> <div class="col-md-8 col-xs-8 q-left-content"> <div class="q-ltop-content"> <a href="<?php the_permalink(); ?> " class="question-title"> <?php the_title(); ?> </a> </div> <div class="q-lbtm-content"> <div class="question-excerpt"> <?php the_excerpt(); ?>
/** * Delete a answer and child answers * @param int $id * @param bool $force_delete * @return bool $success */ public static function delete($id, $force_delete = false) { $instance = self::get_instance(); $answer = get_post($id); $question = get_post($answer->post_parent); $answer = QA_Answers::convert($answer); $question = QA_Questions::convert($question); /* also delete question likes */ $comments = get_comments(array('post_id' => $id, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish')); if (is_array($comments) && count($comments) > 0) { foreach ($comments as $comment) { wp_delete_comment($comment->comment_ID, $force_delete); } } $success = $instance->_delete($id, $force_delete); if ($success) { //update answer count $count = et_count_user_posts($answer->post_author, 'answer'); update_user_meta($answer->post_author, 'et_answer_count', $count); //update status answered for question: $is_best_answer = get_post_meta($id, 'et_is_best_answer', true); if ($is_best_answer) { delete_post_meta($question->ID, 'et_best_answer'); } } return $success; }
<?php global $post; $answer = QA_Answers::convert($post); $question = QA_Questions::convert(get_post($answer->post_parent)); $et_post_date = et_the_time(strtotime($answer->post_date)); $badge_points = qa_get_badge_point(); $category = !empty($question->question_category[0]) ? $question->question_category[0]->name : __('No Category', ET_DOMAIN); $category_link = !empty($question->question_category[0]) ? get_term_link($question->question_category[0]->term_id, 'question_category') : '#'; ?> <li <?php post_class('answer-item question-item pending-question'); ?> data-id="<?php echo $post->ID; ?> "> <div class="col-md-8 q-left-content"> <div class="q-ltop-content title-answer-style"> <a href="<?php echo get_permalink($question->ID); ?> " class="question-title"> <?php the_title(); ?> </a> </div> <div class="q-lbtm-content"> <div class="question-cat"> <span class="author-avatar">
/** * * TEMPLATE LOOP FOR ANSWERS * @param array $answers * @author ThaiNT * @since 1.0 * **/ function qa_answers_loop() { global $post, $wp_rewrite, $current_user, $qa_question; $question_ID = $post->ID; $answersData = array(); $commentsData = array(); $question = QA_Questions::convert(get_post($question_ID)); $qa_question = $question; $paged = get_query_var('page') ? get_query_var('page') : 1; $reply_args = array('post_type' => 'answer', 'post_parent' => $post->ID, 'paged' => $paged); //show pending answer if current user is admin if (is_user_logged_in() && (qa_user_can('approve_answer') || current_user_can('manage_options'))) { $reply_args['post_status'] = array('publish', 'pending'); } if (isset($_GET['sort']) && $_GET['sort'] == "oldest") { $reply_args['order'] = 'ASC'; } else { add_filter("posts_join", array("QA_Front", "_post_vote_join")); add_filter("posts_orderby", array("QA_Front", "_post_vote_orderby")); } $replyQuery = new WP_Query($reply_args); ?> <!-- ANSWERS LOOP --> <div id="answers_main_list"> <?php if ($replyQuery->have_posts()) { while ($replyQuery->have_posts()) { $replyQuery->the_post(); global $post, $qa_answer, $qa_answer_comments; $qa_answer = QA_Answers::convert($post); $answersData[] = $qa_answer; $qa_answer_comments = get_comments(array('post_id' => $qa_answer->ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'answer')); $commentsData = array_merge($commentsData, $qa_answer_comments); ?> <div class="row question-main-content question-item answer-item" id="<?php echo $qa_answer->ID; ?> "> <?php get_template_part('template/item', 'answer'); ?> </div><!-- END REPLY-ITEM --> <?php } } wp_reset_query(); ?> </div> <!-- ANSWERS LOOP --> <div class="row paginations <?php echo $replyQuery->max_num_pages > 1 ? '' : 'collapse'; ?> "> <div class="col-md-12"> <?php echo paginate_links(array('base' => get_permalink($question_ID) . '%#%', 'format' => $wp_rewrite->using_permalinks() ? 'page/%#%' : '?paged=%#%', 'current' => max(1, $paged), 'total' => $replyQuery->max_num_pages, 'mid_size' => 1, 'prev_text' => '<', 'next_text' => '>', 'type' => 'list')); ?> </div> </div><!-- END PAGINATIONS --> <script type="text/javascript"> <?php $parent_comments = get_comments(array('post_id' => $question_ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'question')); $commentsData = !empty($commentsData) ? $commentsData : array(); ?> var answersData = <?php echo defined('JSON_HEX_QUOT') ? json_encode($answersData, JSON_HEX_QUOT) : json_encode($answersData); ?> ; var commentsData = <?php echo defined('JSON_HEX_QUOT') ? json_encode(array_merge($parent_comments, $commentsData), JSON_HEX_QUOT) : json_encode(array_merge($parent_comments, $commentsData)); ?> ; </script> <?php }
/** * AJAX search questions by keyword (next version) * */ public function search_questions() { try { $query = QA_Questions::search($_POST['content']); $data = array(); foreach ($query->posts as $post) { $question = QA_Questions::convert($post); $question->et_avatar = QA_Member::get_avatar_urls($post->post_author, 30); $question->permalink = get_permalink($post->ID); $data[] = $question; } $resp = array('success' => true, 'msg' => '', 'data' => array('questions' => $data, 'total' => $query->found_posts, 'count' => $query->post_count, 'pages' => $query->max_num_pages, 'search_link' => qa_search_link($_POST['content']['s']), 'search_term' => $_POST['content']['s'], 'test' => $query)); } catch (Exception $e) { $resp = array('success' => false, 'msg' => $e->getMessage()); } wp_send_json($resp); }
<?php global $post, $wp_rewrite, $current_user, $qa_question, $qa_answer; the_post(); $answer = QA_Questions::convert($post); $question = QA_Questions::convert(get_post($post->post_parent)); $et_post_date = et_the_time(strtotime($question->post_date)); $category = !empty($question->question_category[0]) ? $question->question_category[0]->name : __('No Category', ET_DOMAIN); $category_link = !empty($question->question_category[0]) ? get_term_link($question->question_category[0]->term_id, 'question_category') : '#'; /** * global qa_question */ $qa_question = $question; $qa_answer = $answer; get_header(); $parent_comments = get_comments(array('post_id' => $question->ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'question')); $qa_answer_comments = get_comments(array('post_id' => $qa_answer->ID, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish', 'order' => 'ASC', 'type' => 'answer')); $commentsData = array_merge($parent_comments, $qa_answer_comments); ?> <?php get_sidebar('left'); ?> <div class="col-md-8 main-content single-content"> <div class="row select-category single-head"> <div class="col-md-2 col-xs-2"> <span class="back"> <i class="fa fa-angle-double-left"></i> <a href="<?php echo home_url(); ?> "><?php _e("Home", ET_DOMAIN);