Solved

Getting an error from implode function in custom Wordpress Theme

Posted on 2013-01-18
5
664 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 110

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 8

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 8

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

734 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