Output comma with get_field in Advanced Custom Fields

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I would like to output the name and the degree in this format: John Doe, PhD

My code is as follows:

$degree = get_field( 'degree', $post->ID );
<h4 class="block-slider-faculty__slide__details__title"><?php the_title(); ?><?php echo implode(', ', $degree); ?></h4>

I got a "Warning: Implode(): invalid arguments passed in…" error.

I believe I need to put the $degree in an array? Please let me know how I can do that with the code above. Thank you for your help.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I would like to output the name and the degree in this format: John Doe, PhD

My code is as follows:

$degree = get_field( 'degree', $post->ID );
<h4 class="block-slider-faculty__slide__details__title"><?php the_title(); ?><?php echo implode(', ', $degree); ?></h4>

I got a "Warning: Implode(): invalid arguments passed in…" error.

I believe I need to put the $degree in an array? Please let me know how I can do that with the code above. Thank you for your help.

Share Improve this question edited Dec 11, 2019 at 19:16 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Dec 11, 2019 at 18:16 user3298611user3298611 535 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

implode() is intended to take an array and convert it to a string. Unless the value of $degree is an array, you're going to get an error.

If $degree is already a string value, there's no need to implode() it.

I'm guessing here because you didn't include any information in your question about where the name comes from and if the "degree" field is simply the degree. So the following is based on an assumption that the_title() is the name and $degree simply contains the degree as a string (such as "PhD").

$degree = get_field( 'degree', $post->ID ); <h4 class="block-slider-faculty__slide__details__title"><?php the_title(); ?>, <?php echo $degree; ?></h4>

Of course, if there is a possibility that $degree is empty, you'd have to also account for that, so the following might be better in that regard:

$degree = get_field( 'degree', $post->ID ); $degree_output = ( $degree ) ? ", " . $degree : ''; <h4 class="block-slider-faculty__slide__details__title"><?php the_title(); echo $degree_output; ?></h4>

(Also note above, there's no need in the second example (nor your original) to close PHP and then reopen it right away.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744915813a4600827.html

相关推荐

  • Output comma with get_field in Advanced Custom Fields

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    1天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信