$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>two custom fields question|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

two custom fields question

matteradmin7PV0评论

Two questions

  1. I need an updated code for this question

  2. How can I hide the value if there is no value entered?

My value would be a link, and this is my current code

<a href="<?php echo get_post_meta($post->ID, 'mp3_link1', true); ?>" target="_blank">MP3</a>

I need to do this without any plugins.

Two questions

  1. I need an updated code for this question

  2. How can I hide the value if there is no value entered?

My value would be a link, and this is my current code

<a href="<?php echo get_post_meta($post->ID, 'mp3_link1', true); ?>" target="_blank">MP3</a>

I need to do this without any plugins.

Share Improve this question edited Feb 18, 2019 at 21:01 Nathan Johnson 6,5386 gold badges30 silver badges49 bronze badges asked Jan 20, 2019 at 22:42 user159405user159405 1
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, consider taking a look at: How does deleting work? – iBooot Commented Feb 18, 2019 at 20:47
Add a comment  | 

1 Answer 1

Reset to default 1

All you have to do to hide this link is to check, if it's empty:

<?php if ( $link = get_post_meta($post->ID, 'mp3_link1', true) && trim($link) ) : ?>
    <a href="<?php echo esc_attr($link); ?>" target="_blank">MP3</a>
<?php endif; ?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far