View Single Post
Old 04-13-2020, 07:14 AM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,080
Quote:
Originally Posted by seoguy View Post
solved...

for anybody who runs into such a (similar) problem, this works:

$externalurl = get_post_meta( get_the_ID(), 'ExternalUrl', true);
if( ! empty( $externalurl) ) {
$externalurl = get_post_meta($post->ID, 'ExternalUrl', true);
$output .= '<a href="' . get_post_meta( get_the_ID(), 'ExternalUrl', true) . '" class="entry-featured-image-url" target="_blank">';
} else{
$output .= '<a href="' . esc_url( get_the_permalink( $post_id ) ) . '" class="entry-featured-image-url">';
}
First, congrats on working through it.

Second, here is a little cleaned up version of the same thing for you. Once you pull the externalurl into the $externalurl variable, use that for the output. Since you do that at the start, you do not have to re=-do it inside the if.

$externalurl = get_post_meta( get_the_ID(), 'ExternalUrl', true);
if( ! empty( $externalurl) )
{
$output .= '<a href="' . $externalurl . '" class="entry-featured-image-url" target="_blank">';
}
else
{
$output .= '<a href="' . esc_url( get_the_permalink( $post_id ) ) . '" class="entry-featured-image-url">';
}

Hope that helps.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote