WordPress.org

Ready to get started?Download WordPress

Forums

Magic Fields 2
Display custom fields on a custom template via get_post (1 post)

  1. Drding
    Member
    Posted 9 months ago #

    Hi I'm currently using MF2 on a restaurant project.

    I had some great success creating a post and adding some custom fields to it. The way I'm working with MF2 is I've created a group called "Menu Item" and it's repeatable. And then within that group I've created two fields: Name and Description. So for example I made a Specials post and then added menu item names and descriptions to that. It worked great and displayed on the home page with this piece of code:

    <div id="specials">
    
    <?php
    $query2 = get_post(32);
    $title = $query2->post_title;
    ?>
    	<div id="specialstitle"><?php echo $title; ?></div>
    	<div class="stripebackbrown">&nbsp;</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>';
    
    } ?>
    	</div>
    
    </div><!-- end specials-->

    My plan was to create posts for each section of the menu, add related items to that, and then pull up the posts in various places on the site.
    One place in particular is my Menu page (basically this has the entire restaurant's menu on it). This page is built with a custom page template. I tried to call up the Specials post (using the code above) on this page and while the $title part is displaying, the menu items array is not. That "specialslist" div is empty.

    I don't know if it's because I'm using the above code on a custom page template or what, but any help would be greatly appreciated. If you need any more information just let me know.

    http://wordpress.org/plugins/magic-fields-2/

Reply

You must log in to post.

About this Plugin

About this Topic