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

  • '$customID' is a string, have you tried $customID? – Milo Jun 2 '17 at 15:14
  • thanks milo i just update my question i typed it wrongly – Mouner Mostafa Jun 2 '17 at 15:18
  • How are you getting $customID? – czerspalace Jun 2 '17 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. – Andrew Dinmore Jun 2 '17 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 – Mouner Mostafa Jun 4 '17 at 23:54
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, privacy policy and cookie policy

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