Custom field/meta populated by dropdown of existing posts?

(My first WP question ever asked! Be gentle!)

I’m building a site that is mostly pages (i.e., static), using WP as CMS. At the bottom of several of the pages, there will appear 1, 2, or 3 “promo boxes” — basically button-images that link to other parts of the site. Though only up to 3 promo boxes will appear on any given page, there will be ~30 different ones to choose from.

When my client creates a new page, I’d like him to be able to choose promo boxes from something like a dropdown list of all of the possible promo boxes.

Seems to me this should work like this:

  • Create a custom post type called “promo-box”. (Though it could just as easily be a tag for regular posts.)
  • Use a tool like Custom Field Template to create a dropdown on the page editor, where the values of the dropdown options are dynamically generated from the list of all existing promo-box posts. (This is the part I don’t know how to do.)
  • Access the resulting metadata (post number is really all I need, then I can get everything else) on the page template.

Based on responses to other questions here, I have taken initial looks at WPAlchemy MetaBox, Posts-2-Posts, and SLT Custom Fields, but I confess the documentation for each of them is slightly geekier than I am, so I haven’t delved too deeply.

Advice? Is one of the above tools the right solution for me, and I just have to figure it out? Am I missing something here?

2 s
2

As the author of WPAlchemy, I’m a bit bias, but you essentially have a good working model outlined to follow depending on what ever route you choose.

However, if using WPAlchemy, you would basically do something like the following (step #2):

//  functions.php

include_once 'WPAlchemy/MetaBox.php';

if (is_admin()) 
{
    // a custom style sheet if you want to do some fancy styling for your form
    wp_enqueue_style('custom_meta_css', TEMPLATEPATH . '/custom/meta.css');
}

// define the meta box
$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/meta.php'
));

custom/meta.css can contain styles that you can style your form with and custom/meta.php is essentially an HTML file with the FORM contents of the meta box, in this case your drop down, to generate your drop down you would do a custom wp query to get all your custom post types. WPAlchemy has some special helper functions to aid in creating your form elements.

There is additional documentation to assist you when working in the template.

The main goal of WPAlchemy was to keep control in the hands of the developer, from styling (look + feel) to meta box content definition.

And myself and others are always willing to help those who comment and ask questions.

Leave a Comment