Skip to content
This repository was archived by the owner on Jul 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions acf-autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ public function autocomplete_ajax_callback() {

//$results = array( 'post' => $_POST, 'get' => $_GET );

$results = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT postmeta2.meta_value FROM $wpdb->postmeta as postmeta1, $wpdb->postmeta as postmeta2 WHERE postmeta1.meta_value = '%s' AND postmeta1.meta_key = CONCAT( '_', postmeta2.meta_key ) AND postmeta2.meta_value LIKE %s",
$_REQUEST['field_key'],
'%' . $_REQUEST['request'] . '%'
) );
$results = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT meta_value FROM {$wpdb->postmeta}
WHERE meta_key = '%s'
AND meta_value LIKE %s
", $_REQUEST['field_key'], '%'.$_REQUEST['request'].'%' ) );

echo json_encode($results);


wp_die();

}
Expand Down
8 changes: 4 additions & 4 deletions js/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function($){


function initialize_field( $el ) {
function initialize_field( $el, field_name ) {

$(':text:visible',$el).autocomplete({
source: function( request, response ){
Expand All @@ -11,7 +11,7 @@

$.getJSON( ajaxurl, {
'action' : 'autocomplete_ajax',
'field_key' : $el.data('field_name'),
'field_key' : field_name,
'request' : request.term.trim()
}, function( data ){

Expand All @@ -33,7 +33,7 @@
// search $el for fields of type 'autocomplete'
acf.get_fields({ type : 'autocomplete'}, $el).each(function(){

initialize_field( $(this) );
initialize_field( $(this), $(this).data('name') );

});

Expand All @@ -51,7 +51,7 @@

$(postbox).find('.field[data-field_type="autocomplete"]').each(function(){

initialize_field( $(this) );
initialize_field( $(this), $(this).data('field_name') );

});

Expand Down