0

I have custom fields to display in a post. But all of the custom fields are displaying in a single continuous line, while i want them in separate lines. I am not a coder. I tried <br>, <li> but still no luck. I also searched in stack exchange and web for similar problem, but could not get answer. Please help.

Below is the Code i have in single.php after - while ( have_posts() ) : the_post(); $key_name = get_post_custom_values ($key = 'country'); echo 'Country : ', $key_name[0]; $key_name = get_post_custom_values ($key = 'status'); echo 'Status : ', $key_name[0];

The result in the post is as below:

Country : Saudi ArabiaStatus : Announced

I want it to appear it like the one below:

Country : Saudi Arabia

Status : Announced

2 Answers 2

0

Probably not the best solution, but why don't you try the following:

while ( have_posts() ) : the_post(); ?>
<div><?php $key_name = get_post_custom_values ($key = 'country'); echo 'Country : ', $key_name[0]; ?> </div>
<div><?php $key_name = get_post_custom_values ($key = 'status'); echo 'Status : ', $key_name[0]; ?> </div>
3
  • I tried <div> and get this message - "There has been a critical error on your website. Learn more about debugging in WordPress." Apr 29, 2020 at 14:25
  • Please, make sure that you entered php mode again after the last closing div: <?php Hope that helps!
    – Ivo
    Apr 29, 2020 at 15:16
  • added <?php after the last closing div. Still i get debugging error as told above. Apr 29, 2020 at 16:15
0

I found a solution based on the answer provided by user4379653 here https://stackoverflow.com/questions/27636676/php-line-break-not-working

I used <br /> in echo from the second custom field, as the first field would not require.

$key_name = get_post_custom_values ($key = 'status'); echo '<br />Status : ', $key_name[0];

Thanks to Ivo for trying to help.

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.