[wp-trac] [WordPress Trac] #46355: get_page_by_title() doesnt work if title has an apostrophe ( ‘ )

WordPress Trac noreply at wordpress.org
Fri Mar 1 10:12:09 UTC 2019


#46355: get_page_by_title() doesnt work if title has an apostrophe ( ‘ )
-------------------------------+-------------------------------
 Reporter:  WPnerdzz           |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  5.1
 Severity:  normal             |  Resolution:
 Keywords:  needs-patch        |     Focuses:  coding-standards
-------------------------------+-------------------------------

Comment (by WPnerdzz):

 Replying to [comment:1 immeet94]:
 > Hi, @WPnerdzz thanks for your ticket and welcome to WordPress Trac :)
 > you try to use sanitize_title() function for the getting title.
 >
 > here the example for:
 > $content   = sanitize_title( $content );
 >
 How can I use **sanitize_title()** inside **get_page_by_title()**?
 sanitize_title() outputs something like alexs-book-collection which is not
 the title so the get_page_by_title() function doesnt work.
 I can make a workaround like this,

 {{{
 url_to_postid( get_site_url().'/release_link/'.sanitize_title(
 get_the_title() ).' - '.$lz_version );
 }}}
 but it has a major flaw because if I change the title of a post, the url
 doesnt change automatically (which is a good thing for other purposes) so
 it wont work. And this site has hundred of entries everyday so editing
 both title and permalink is very inefficient.
 And the actual bug we are talking about is, if a title has apostrophe,
 get_page_by_title() wont work. I am looking for a fix for this.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46355#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list