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( 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.
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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!