몇 개월 동안 자동 완성 필드가 작동했지만 로그인하지 않았을 때 작동이 중지 되었습니까? 언제 며칠 또는 몇 주일인지 확실하지 않습니다 (최근에 WordPress를 업데이트하지 않음).
이미; add_action ( 'wp_ajax_filter_schools', 'filter_schools'); add_action ( 'wp_ajax_nopriv_filter_schools', 'filter_schools');
functions.php에 오류가 없습니다.
로그인하지 않을 때받는 응답은 다음과 같습니다.
safari에서 ... * 요청 URL : http : //www.payingforit.org.uk/wp-admin/admin-ajax.php? term = holywe & action = filter_schools & postType = school 요청 방법 : GET 상태 코드 : 302 발견 *
어떤 도움을 환영합니다! Dc.
jquery 코드
$( "#userSelectedSchool" ).bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
}).autocomplete({
source: function( request, response ) {
$.getJSON( "/wp-admin/admin-ajax.php", {
term: extractLast( request.term ), action: 'filter_schools', postType: 'school'
}, response );
dataToBeSent = {
term: extractLast( request.term ), action: 'filter_schools', postType: 'school'
}
console.log(request.term);
}, select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.id );
// add placeholder to get the comma-and-space at the end // ui.item.label
terms.push( "" );
this.value = ui.item.label;
$('input[name=userSchool]').val(ui.item.urn)
return false;
}, open: function() { $('.ui-menu').width(300) }
});
functions.php의 함수
add_action('wp_ajax_filter_schools', 'filter_schools');
add_action('wp_ajax_nopriv_filter_schools', 'filter_schools');
function filter_schools(){
global $wpdb; // this is how you get access to the database
$str = $_GET['term'];
$action = $_POST['action'];
$postType = $_POST['postType'];
$finalArgs = array (
'posts_per_page'=>5,
'order' => 'ASC',
'post_type' => 'school'
);
$searchSchools = new WP_Query( $finalArgs );
$mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title LIKE '".$str."%' ");
$args = array(
'post__in'=> $mypostids,
'post_type'=>'school',
'orderby'=>'title',
'order'=>'asc'
);
$res = new WP_Query($args);
while( $res->have_posts() ) : $res->the_post();
global $post;
$EstablishmentNumber = get_post_meta($post->ID,'EstablishmentNumber', true);
$URN = get_post_meta($post->ID,'URN', true);
$add = get_post_meta($post->ID,'address', true);
$schl = array('post_id'=>$post->ID,'id'=>$EstablishmentNumber, 'label'=>$post->post_title.', '.$add['town'].' '.$add['postcode'] , 'value'=>$EstablishmentNumber, 'urn'=>$URN );
$matchedSchools[] = $schl;
endwhile;
echo json_encode($matchedSchools);
wp_reset_postdata();
die(); // this is required to return a proper result
}