I'm still somewhat a beginner to PHP, so sorry if this is a dumb question =)
What I'm trying to do is in a WordPress blog, insert a custom field with multiple values ("ingredients") into my RSS feed. (I also have other posts which are not recipes, which is why the headings "Ingredients" and "Instructions" are inside the if statement.) Here is my entire code so far:
<?php
function insertIngredients($content) {
/* get ingredients into variable $recipeStuff */
$recipeStuff =
if ($ingredients = get_post_custom_values('ingredients')) {
echo '<h3>Ingredients</h3><ul id="ingredients">';
foreach ( $ingredients as $key => $value ) {
echo '<li>';
echo $value;
echo '</li>';
}
echo '</ul><h3>Instructions</h3>';
}
/* add before content */
$content = $recipeStuff . $content;
return $content;
}
/* Do it! */
add_filter('the_excerpt_rss', 'insertIngredients');
add_filter('the_content_rss', 'insertIngredients');
?>
But a get an "unexpected IF" error, so I guess I can't put all that inside the $recipeStuff variable =) I just can't think of how else to put it in there.
(If it matters, the IF statement is exactly what I use in the posts on the page itself, and it works perfectly!)
Thanks very much in advance for any help! =D
UPDATE!
Here's what I have in my code now:
function insertIngredients($content) {
/* test for presence of ingredients & set variables */
if ($ingredients = get_post_custom_values('ingredients')) {
$heading1 = '<h3>Ingredients</h3><ul id="ingredients">';
foreach ( $ingredients as $key => $value ) {
$ings = '<li>' . $value . '</li>';
}
$heading2 = '</ul><h3>Instructions</h3>';
}
/* if no ingredients, variables are empty */
else { $heading1=''; $ings=''; $heading2=''; }
$recipeStuff = $heading1 . $ings . $heading2 ;
/* add before content */
$content = $recipeStuff . $content;
return $content;
}
/* Do it! */
add_filter('the_excerpt_rss', 'insertIngredients');
add_filter('the_content_rss', 'insertIngredients');
I no longer get an error message, but the ingredients are not showing up in the rss feed. I'm not sure if it's because something is still wrong with the code, or if it takes a while to have an effect (though I don't know why that would be the case)? I use FeedBurner, if that makes a difference.
Thanks very much for your answers, everyone. I'm going to try a few different things and update again in a bit. Thanks! =)