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 questionI 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.
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 questionI 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.
1 Answer
Reset to default 1implode()
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
评论列表(0条)