0

hello am trying to check if there's a url to the custom post type inside default post type page so i used

if(get_the_permalink($customID)){
echo 'true';
}else{
echo 'false';
}

it's always echo true even if the $customID not exists is there's way to do that with get_the_permalink(); function and i know about get_post_status() but i need to do it with get_the_permalink

5
  • '$customID' is a string, have you tried $customID?
    – Milo
    Commented Jun 2, 2017 at 15:14
  • thanks milo i just update my question i typed it wrongly Commented Jun 2, 2017 at 15:18
  • How are you getting $customID? Commented Jun 2, 2017 at 16:21
  • Either your problem is elsewhere or you need to add more detail to this question. get_the_permalink definitely returns false if the post ID passed to it doesn't exist. Commented Jun 2, 2017 at 16:25
  • am using it inside loop so if $customID value is empty the function get the default post url so it's alway return true Commented Jun 4, 2017 at 23:54

1 Answer 1

1

You just need to check if $customID is set, first. E.g.

if ($customID && get_permalink ($customID)) {
    echo 'true';
} else {
    echo 'false';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.