Home Forums General Issues Apostrophe/single quote issue


Apostrophe/single quote issue

  • I am grabbing and matching some custom field data by using the following code…

    $args     = array(
        'numberposts' => -1,
        'post_type' => 'release',
        'meta_key' => 'artist_name',
        'meta_value' => get_the_title(),
        'orderby' => 'date',
        'order' => 'DESC'
    $my_query = null;
    $my_query = new WP_Query($args);
    if ($my_query->have_posts())
        echo '';
        $i = 0;
        while ($my_query->have_posts()):
            if ($i % 6 == 0)

    It works fine until my TITLE has an apostrophe. For example if TITLE = FRED it matches fine, but if the TITLE is O’FRED it fails.
    Does that mean we can’t use any titles with apostrophes/single quotes?

    EDIT: Just noticed if I use a BACKTICK (`) instead of an apostrophe(‘) it allworks. Thought I’d mention that as it might help?

  • Old question, but some additional information. WP is converting the single quote in the title to a special character for display, while the ACF field is not. What you’ll need to do in this case is hunt down the filters that WP is applying to post titles and apply them to the ACF field using an acf/update_value filter to make sure that the values match.

    You might want to think about using a relationship or post object field because these fields store the post ID of the related post(s). This is easier to query for and will not cause problems in the future should the title of the post change or WP decides to treat them differently.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Apostrophe/single quote issue’ is closed to new replies.