Solved

Getting an error from implode function in custom Wordpress Theme

Posted on 2013-01-18
5
646 Views
Last Modified: 2013-01-19
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

0
Comment
Question by:Alicia St Rose
  • 2
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38796411
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
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 38796685
greetings  laughhearty, , ,
It may be possible to get arrays, but I think that the  get_field('my_field') is suppose to return a String for a FIELD source to add and display on your web page, but if get_field is set to have an array returned then your
echo 'Day: ' . implode(', ', get_field('workshop01_day') . ' |');

has the ) in the wrong Place, I would think this is more correct -
echo 'Day: ' . implode(', ', get_field('workshop01_day') ). ' |';

I can explain some if you need to know more (if you are writing this code, not just copy it)
0
 
LVL 7

Author Closing Comment

by:Alicia St Rose
ID: 38797200
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.
0
 
LVL 7

Author Comment

by:Alicia St Rose
ID: 38797208
Slick182 is my error that I concatenated a string in my array?
0
 
LVL 33

Expert Comment

by:Slick812
ID: 38797720
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 ' |'
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now