Commit 0599915e authored by Michael Iseard's avatar Michael Iseard
Browse files

Rename to match class

parent 8de0aa9b
<?php
namespace App;
use App\Controllers\TemplateFaq;
class Ajax {
public function __construct() {
add_action( 'wp_ajax_get_questions', [ $this, 'get_questions' ] );
add_action( 'wp_ajax_nopriv_get_questions', [ $this, 'get_questions' ] );
}
public function get_questions() {
// Check for nonce security
if ( ! wp_verify_nonce( $_POST['nonce'], 'ajax-nonce' ) ) {
die ( 'Nonce verification failed!' );
}
$category = isset( $_POST['category'] ) ? $_POST['category'] : null;
$keywords = isset( $_POST['keywords'] ) ? $_POST['keywords'] : null;
$out = '<p>' . __( 'Sorry, no results were found.', 'kudos-website' ) . '</p>';
$templateFaq = new TemplateFaq();
$questions = $templateFaq->questions( $category, $keywords );
if ( $questions->have_posts() ) :
$out = '';
while ( $questions->have_posts() ) : $questions->the_post();
$out .= template( "partials.content-faq" );
endwhile;
endif;
wp_send_json( $out );
wp_die();
}
}
new Ajax();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment