In my theme I have custom field ‘ext_url’. Now I want to get post url If I don’t add ‘ext_url’ custom field.
I tried
<?php if(get_post_meta($post->ID, 'ext_url', true)): ?>
<?php else : ?>
<?php the_permalink(); ?>
<?php endif; ?>
When I don’t add custom field, it is showing post URL. But, when I add custom field it is showing blank. Any Solutions?
Update: I’ve found a code
<?php
$url = get_post_meta($post->ID, 'ext_url', true);
if ($url) {
echo "<p><a href='$url'>External URL</a></p>";
}
?>
but, it is working for showing custom field. How can i add else function here? Sorry, I am not experienced in PHP.
If you want it to display the data from the custom field, you should add a line to echo the results.