Forums

[resolved] Custom Fields and Custom Write Panel (6 posts)

  1. Jacorre
    Member
    Posted 1 year ago #

    I've been following this tutorial Revisited Creating Custom Write Panels in WordPress on creating a custom write panel and I've gotten it to appear successfully.

    My question is how do I get all of my previous posts with custom fields defined already to populate the new custom write panel?

    It would be easier to use the custom write panel for future posts, but if I have to go back and define the data in that format for previous posts, that would be one heck of an undertaking!

    Any suggestions are appreciated!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    if you make the $key the same as your old custom field $key it will be using that to show in the metabox.

    $key = "key";

  3. Jacorre
    Member
    Posted 1 year ago #

    Thanks for the quick response.

    I thought that the variable $key at the top of the script was only being used to label the write panel?

    I am using the names of the custom fields I already have defined as the same names in the array to define the custom write panel fields.

    For example, I have a custom field called thumbnail.

    So in my array, I have:

    $key = "key";
    $meta_boxes = array(
    "thumbnail" => array(
    "name" => "thumbnail",
    "title" => "Thumbnail",
    "description" => "Enter the Thumbnail URL.")

    Are you saying that the $key value should be thumbnail?

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    I just read they store their $_POST data as a serialized array.
    in this tutorial they save the $_POST data as individual custom fields: http://www.deluxeblogtips.com/2010/05/howto-meta-box-wordpress.html
    Just remove the prefix from the custum field key (id) to let the metabox use your custom field key:
    so this:

    'fields' => array(
            array(
                'name' => 'Text box',
                'desc' => 'Enter something here',
                'id' => $prefix . 'text',
                'type' => 'text',
                'std' => 'Default value 1'
            )
        )

    will become this:

    'fields' => array(
            array(
                'name' => 'image',
                'desc' => 'Enter something here',
                'id' => 'thumbnail', // your custom field key
                'type' => 'text',
                'std' => 'Default value 1'
            )
        )
  5. Jacorre
    Member
    Posted 1 year ago #

    I will give that a try thank you!

  6. Jacorre
    Member
    Posted 1 year ago #

    Works great thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic