0

I'm using jQuery UI autocomplete for three different form suggestions. Everything is working good, the only issue is that titles suggested aren't utf-8 (I think):

Instead of "Bla bla - Bla" I have "Bla bla &#8211 Bla"

This is my js:

$('.ricerca-mirata input').focus(function() {
        var postType = $(this).data('tipo');
        var url = aela.ajax_url + "?action=my_search&post_type=" + postType;
        $( ".autocomplete" ).autocomplete({
            source: url,
            delay: 500,
            minLength: 3
        }); 
    });

And my php:

function my_search() {
    $term = strtolower( $_GET['term'] );
    $post_type = $_GET['post_type'];
    $suggestions = array();

    $loop = new WP_Query( array(
        's' => $term,
        'post_type' => $post_type,
        'post_status' => 'publish'

        ) );

    while( $loop->have_posts() ) {
        $loop->the_post();
        $suggestion = array();
        $suggestion['label'] = get_the_title();
        $suggestion['link'] = get_permalink();

        $suggestions[] = $suggestion;
    }

    wp_reset_query();

    $response = json_encode( $suggestions );

    echo $response;
    exit();

}

Have you got any ideas? Thank you very much for your help!

0

Remove the filter wptexturize, which is what's causing your encoding issue:

remove_filter( 'the_title', 'wptexturize' );
while ( $loop->have_posts() ) {
    // Your code
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.