admin管理员组

文章数量:1335847

I'm repairing an old site on which we match the titles of two types of posts to link them together. There is a wp_query which uses 'title' => get_the_title() to do this, but it only works some of the time.

My first solution was to clean the title string using html_entity_decode(). This works on 90% of cases and I need to retain this processing to deal with these posts.

However I am now stuck with a particular outlier, which has a title like this It’s Raining Outside My Mother’s House.

  • If I compare == the two values, with no preprocessing, it returns true, but via the query it fails.

  • If I paste the title value into the query it works, and if I use addslashes() it still works.

  • But if I use get_the_title() in the query (as I need to for the final code) it fails, even if I use addslashes().

Is there another function I need in order to clean the title string? Can you suggest an 'all cases' technique?

Thanks

I'm repairing an old site on which we match the titles of two types of posts to link them together. There is a wp_query which uses 'title' => get_the_title() to do this, but it only works some of the time.

My first solution was to clean the title string using html_entity_decode(). This works on 90% of cases and I need to retain this processing to deal with these posts.

However I am now stuck with a particular outlier, which has a title like this It’s Raining Outside My Mother’s House.

  • If I compare == the two values, with no preprocessing, it returns true, but via the query it fails.

  • If I paste the title value into the query it works, and if I use addslashes() it still works.

  • But if I use get_the_title() in the query (as I need to for the final code) it fails, even if I use addslashes().

Is there another function I need in order to clean the title string? Can you suggest an 'all cases' technique?

Thanks

Share Improve this question asked May 30, 2020 at 8:29 byzantine cucumberbyzantine cucumber 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Solved. After much digging I eventually came upon this:

remove_filter ('the_title', 'wptexturize');

本文标签: phpTrouble matching strings (titles) using wpquery