0

I have the following code, and I am attempting to concatenate the values of the echo html code & 'the_meta'. Can anyone please suggest an edit to code to get this working?

CURRENT CODE

<?php echo '<p style="text-align:left;font-size:18px;margin-bottom:5px;">
<span style="color: #000000;">By AUTHOR FOR</span> <?php the_meta(); ?>  </p>'; ?>

DESIRED RESULT

By AUTHOR FOR A GREAT MAGAZINE

2 Answers 2

1

To display the_meta () after the 'by author for' text just needs a small change:

<p style="text-align:left;font-size:18px;margin-bottom:5px;"><span style="color: #000000;">By AUTHOR FOR</span> <?php the_meta (); ?></p>

However I'm not sure you want to use the_meta (), because all values get displayed, and in an unordered list. (Reference: the_meta.)

Instead you probably want get_post_meta, so:

<p style="text-align:left;font-size:18px;margin-bottom:5px;"><span style="color: #000000;">By AUTHOR FOR</span> <?php echo get_post_meta (get_the_ID (), 'my-author-meta-key', true); ?></p>

Replacing my-author-meta-key with your meta key name, obviously.

0

Did you try adding echo ""; inside the tag like this:

 <?php the_meta(echo "somethin" ); ?>
2
  • I would like the value of the html echo first and then the value of 'meta_data' second. Presumably the above wouldn't achieve this? Jan 4, 2017 at 20:42
  • It's all wrapped in one paragraph, I assume it will appear the order I see it, perhaps you could give it a try Jan 4, 2017 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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