Link to home
Start Free TrialLog in
Avatar of Alicia St Rose
Alicia St RoseFlag for United States of America

asked on

Getting an error from implode function in custom Wordpress Theme

Hi,
I'm getting this error:

Warning: implode() [function.implode]: Invalid arguments passed in /home/lucidity/public_html/wp-content/themes/lucidity-festival/workshop.php on line 57

Open in new window


I think it has something to do with the implode function not having an array, but I'm green at PHP and I don't know how to implement that...

I'm using the Advanced Custom Fields plugin.

here's my code:

<h3>Scheduled Workshops</h3>
								<ul>
							<?php if(get_field('workshop01_title') !=false) { 
								echo '<li><h4 class="workshop-event-title">' . get_field('workshop01_title') . '<br /><span>';
								} ?>
								
								<?php if(get_field('workshop01_day') !=false) {
								echo 'Day: ' . implode(', ', get_field('workshop01_day') . ' |');
								} else {
								echo ' '; 
								} ?>
								<?php if(get_field('workshop01_duration')  !=false) {
								echo 'Duration: ' . get_field('workshop01_duration') . ' min. |';
								} else {
								echo ' ';
								} ?>
								<?php if(get_field('workshop01_stage') !=false) {
								echo 'Location: ' . get_field('workshop01_stage') . '</span></h4>';
								} else {
									echo '</span></h4>';
								} ?>
								<?php
								echo '<p>' . get_field('workshop01_description') . '</p></li>';
							 ?>	
							 <?php if(get_field('workshop02_title') !=false) { 
								echo '<li><h4 class="workshop-event-title">' . get_field('workshop02_title') . '<br /><span>';
								} ?>
								
								<?php if(get_field('workshop02_day') !=false) {
								echo 'Day: ' . implode(', ', get_field('workshop02_day') . ' |');
								} else {
								echo ' '; 
								} ?>
								<?php if(get_field('workshop02_duration')  !=false) {
								echo 'Duration: ' . get_field('workshop02_duration') . ' min. |';
								} else {
								echo ' ';
								} ?>
								<?php if(get_field('workshop02_stage') !=false) {
								echo 'Location: ' . get_field('workshop02_stage') . '</span></h4>';
								} else {
									echo '</span></h4>';
								} ?>
								<?php
								echo '<p>' . get_field('workshop02_description') . '</p></li>';
							 ?>
							 <?php if(get_field('workshop03_title') !=false) { 
								echo '<li><h4 class="workshop-event-title">' . get_field('workshop03_title') . '<br /><span>';
								} ?>
								
								<?php if(get_field('workshop03_day') !=false) {
								echo 'Day: ' . implode(', ', get_field('workshop03_day') . ' |');
								} else {
								echo ' '; 
								} ?>
								<?php if(get_field('workshop03_duration')  !=false) {
								echo 'Duration: ' . get_field('workshop03_duration') . ' min. |';
								} else {
								echo ' ';
								} ?>
								<?php if(get_field('workshop03_stage') !=false) {
								echo 'Location: ' . get_field('workshop03_stage') . '</span></h4>';
								} else {
									echo '</span></h4>';
								} ?>
								<?php
								echo '<p>' . get_field('workshop03_description') . '</p></li>';
							 ?>
							 <?php if(get_field('workshop04_title') !=false) { 
								echo '<li><h4 class="workshop-event-title">' . get_field('workshop04_title') . '<br /><span>';
								} ?>
								
								<?php if(get_field('workshop04_day') !=false) {
								echo 'Day: ' . implode(', ', get_field('workshop04_day') . ' |');
								} else {
								echo ' '; 
								} ?>
								<?php if(get_field('workshop04_duration')  !=false) {
								echo 'Duration: ' . get_field('workshop04_duration') . ' min. |';
								} else {
								echo ' ';
								} ?>
								<?php if(get_field('workshop04_stage') !=false) {
								echo 'Location: ' . get_field('workshop04_stage') . '</span></h4>';
								} else {
									echo '</span></h4>';
								} ?>
								<?php
								echo '<p>' . get_field('workshop04_description') . '</p></li>';
							 ?>
							 </ul>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

something to do with the implode function not having an array
Yes, that is exactly correct.  
http://php.net/manual/en/function.implode.php

The message says the error occurred on line 57 of the script at /public_html/wp-content/themes/lucidity-festival/workshop.php but the code snippet posted here shows that line 57 contains this (which has no implode() statement).

echo 'Duration: ' . get_field('workshop03_duration') . ' min. |';

Open in new window

For that reason, I would suggest that you might want to hire a professional programmer to help you out.  This is a data-dependent problem and the data confusion that lead to the warning message probably occurred somewhere else in the code.  You might look to meetup.com and see if there is a WordPress developers group near you.

Also, and you want to be very careful if you do this, you can suppress the messages from PHP functions.  If you're happy with the output and this warning message is the only thing that is bothering you, just go into the code base, find the implode() statement and prepend the at-sign to the function name.  It will look like @implode().  And while this may work out well for you, it's a little like putting black electrical tape over the warning light on your dashboard.

HTH, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alicia St Rose

ASKER

Thank you Slik812,
That solved my problem! Ray so sorry, I didn't post all the code, only the pertinent piece and that caused line numbers to be off. I am coding this myself, with what crazy little knowledge I know. I needed the fields to show up only if they were filled and I had some pipes in the design that were showing up even though the fields were empty.
Slick182 is my error that I concatenated a string in my array?
OK in your line -
echo 'Day: ' . implode(', ', get_field('workshop01_day') . ' |');
you do not recognize that the function implode always has two parentheses ( ), and that the second parameter after the comma > > (' -', $array1) can only be an array (as your ERROR says), but when you have the  period  and the string . ' |'  inside the  ( ) it changes the array to a string (actually it discards the array because it can not be a string) so your line -
echo 'Day: ' . implode(', ', get_field('workshop01_day') . ' |');
is read by PHP as -
echo 'Day: ' . implode(', ',  ' |');
and so it does not work because the ' |'  is not an array,
you may be thinking that the second  )  is for a finish (close) to the echo or some other code arrangement, , but you always need to have a matching ) for every function's first (
and where you place it so it pulls in the finish of the echo out string ' |'