I am using the below code:
$title = get_the_title($result->post_id);
if ( 0 === post_exists( $title ) ) {
$title = 'Document Id: '.$result->post_id .' (Deleted)';
}
But it's returning 0 if post title contains special characters. I also tried using
$title = esc_attr(get_the_title($result->post_id));
but no luck.
I am using the below code:
$title = get_the_title($result->post_id);
if ( 0 === post_exists( $title ) ) {
$title = 'Document Id: '.$result->post_id .' (Deleted)';
}
But it's returning 0 if post title contains special characters. I also tried using
$title = esc_attr(get_the_title($result->post_id));
but no luck.
Looks like WP is using HTML entity encoding on the special characters, you need to parse the title using the html_entity_decode()
function like so.
$title = html_entity_decode(get_the_title($result->post_id));
if ( 0 === post_exists( $title ) ) {
$title = 'Document Id: '.$result->post_id .' (Deleted)';
}
I am not sure if the post exists function decodes the characters but I am going to assume it does, let me know if you are still getting a 0 though
Comment below any questions!
– : * , . &
– Waleed Commented Oct 3, 2019 at 13:36