Hi there,
I'm using the recipress plugin for a client website that's nearly completed. I've posted yesterday on their forums as well, but haven't gotten any response and it looks like most folks aren't getting timely responses. So I thought I'd ask for some assistance over here.
Basically, the client asked to have the heading "Instructions" changed to "Prescription". I know I could have just changed the language file, but this client isn't very saavy and would have gotten generally confused in the admin area as well so I figured I'd change all instances of "instruction/instructions" and "Instruction/Instructions" in all files. For the most part, everything came out great. The script displays fine and everything. But I'm getting two errors and I don't know how to solve them (I can occasionally figure out how to write my own snippet, but I am no programmer).
Following are the error messages I'm getting:
Warning: Invalid argument supplied for foreach() in /path/wp-content/plugins/recipress/php/functions.php on line 240
Warning: Invalid argument supplied for foreach() in /path/wp-content/plugins/recipress/php/functions.php on line 288
And the two referenced lines of code are identical:
I'm sorry, I don't know what part of the code to post. There are a bunch of files associated with this plugin. Do you just want all the code from the referenced file?
First thing to check is right from the manual:
foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable.
What things should look like:
PHP Code:
<?php $prescriptions = array('step one', 'step two', 'step three', 'step four'); reset($prescriptions); // TO MAKE SURE THE ARRAY IS POINTING AT FIRST ELEMENT
When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. This means that you do not need to call reset() before a foreach loop.
reset() is only required if you have used next() or some other method to move the internal pointer.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Ok. But that's what's on the rows it's saying the errors are in. How would I figure out where else the error would be coming from.
That error means the first argument, $prescriptions, that you are passing to foreach() loop is supposed to be an array, but it isn't. If you dump the $prescriptions variable before the foreach() loop you'll see what the actual value is:
Since I really and truly have no clue what portion of the code I would need to post, I'm going to assume that you need to see the entire "function.php" file contents in order to help me here. The above comments, I'm sure, should make loads of sense if I really knew php at a slightly higher level, but alas I'm still a beginner with it. Hopefully someone will be able to see what the problem is by looking at this?
I should note that I finally HAVE an entry with "Prescriptions" in it, and they do not appear on the page:
// function for outputting recipe items // ---------------------------------------------------- function recipress_recipe($field, $attr = null) { global $post; $meta = get_post_custom($post->ID);
Thank you awfully much. I have somehow solved the issue, though I'm not really sure how. It seems that the recipress plugin doesn't save data to the database or something. When I changed "Instructions" to "Prescriptions", and even searched for the same in PHPMyAdmin, any I had entered were gone. When I re-entered them, the errors disappear. Surely it would be better to have an if/then statement so that if there ARE no "Prescriptions", nothing appears at all. Aw well. I'll work on that later I suppose.