Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Getting an error from implode function in custom Wordpress Theme

Posted on 2013-01-18
5
652 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 109

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 34

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 34

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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