Home Forums Front-end Issues Custom Field Encoding


Custom Field Encoding

  • Hi

    I have run into a tricky issue.

    On a page I am building I am using WordPress WP_Query to compare a custom post type’s ACF field with a custom taxonomy term. This are my args:

    $args = array(
    	'post_type' => 'photographs',
    	'tax_query' => array(
    			'taxonomy' => 'subjects',
    			'field'    => 'name',
    			'terms'    => get_field( 'subject_first_name', get_the_ID() ) . ' ' . get_field( 'subject_last_name', get_the_ID() ),
    	'meta_query' => array(
    	    'photo_date' => array(
    	    	'key' => 'photo_date',
    	    	'type'    => 'NUMERIC',
    	    	'compare' => 'EXISTS',
    	'orderby' => array(
    		'photo_date' => 'ASC',
    	'posts_per_page' => -1,

    The code works fine until the text I am comparing includes an apostrophe. For example, when the text is Georgia O’Keeffe, that is:

    get_field( 'subject_first_name', get_the_ID() ) . ' ' . get_field( 'subject_last_name', get_the_ID() ) = Georgia O'Keeffe


    subjects / name = Georgia O'Keeffe

    I don’t get a match.

    get_field( ‘subject_first_name’, get_the_ID() ) . ‘ ‘ . get_field( ‘subject_last_name’, get_the_ID() ) returns ‘Georgia O'Keeffe’ and the taxonomy query returns ‘Georgia O’Keeffe’.

    I’ve tried using html_entity_decode to convert ' to ‘. But I still get no return.

    To be honest. I am lost and am looking for any pointers to fix this.

    Much appreciated.


  • So … the page has converted every instance of &#039 ; in my post to an apostrophe.

  • Not sure if you’ve figured out your problem or not. If you haven’t can you try to explain a little more about what the problem is?

  • Hi John

    Thanks for posting. I should have posted here a little earlier. I also posted this to WordPress yesterday and got a resolution. I think there is a bug in WordPress which is evident when comparing custom fields and custom taxonomies that contain an apostrophe:

    Applying the code from the above thread to the WordPress core (I know … but it makes sense) fixed my issue alongside wrapping the return I get from an ACF field in html_entity_decode before comparing it with my custom taxonomy.

    Once again, thank you.


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

You must be logged in to reply to this topic.