最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Trouble matching strings (titles) using wp_query

programmeradmin0浏览0评论

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');

发布评论

评论列表(0)

  1. 暂无评论