Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

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

0
Alicia St Rose
Asked:
Alicia St Rose
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
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
 
Slick812Commented:
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
 
Alicia St RoseOwner & Principle Developer/DesignerAuthor Commented:
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
 
Alicia St RoseOwner & Principle Developer/DesignerAuthor Commented:
Slick182 is my error that I concatenated a string in my array?
0
 
Slick812Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now