Referencing a post with custom fields on a page
-
Hi there,
I’m trying to use the Magic Fields 2 plugin to make menus for a restaurant website using WP.
I was able to query a post that contained custom fields on the index page like this:
<?php $query1 = get_post(219); $title = $query1->post_title; echo '<div id="specialstitle">'.$title.'</div>'; ?> <div class="stripebackbrown"> </div> <div id="specialslist"> <?php $itemname = get_post_meta ($post->ID, 'menu_item_name', false); ?> <?php $description = get_post_meta ($post->ID, 'menu_item_description', false); ?> <?php foreach (array_combine($itemname, $description) as $itemname => $description){ echo '<span>' .$itemname. '</span>'; echo '<p>' .$description. '</p>'; } ?>
What this does by the way is display each item name and its description in a list.
Here’s my problem. The above code works on the index.php page but when I try to use it on a page with a custom template I get these two errors:
Warning: array_combine() [function.array-combine]: Both parameters should have at least 1 element in … on line 20
Warning: Invalid argument supplied for foreach() in … on line 20
Any ideas why this works on the index and not on a page? If I can get this working I can make several posts for each menu section (like Lunch or Desert for example) and then just query them and display the output.
I’ve tried creating the same exact group and fields for the page post type by the way (I thought maybe that was it) and I’m still getting the above errors.
Thanks!
- The topic ‘Referencing a post with custom fields on a page’ is closed to new replies.