Monday, 27 May 2013

Save Custom Fields

Save Custom Fields

I am working in a new project using WordPress. I have created some Custom Posts and now I have to relate some custom posts like categories.
I created a custom dropdown menu inside the custom posts. The dropdown displays the title of the customs post but I don´t know how to save them.
Here is my code:
/* add custom field to my customo post */

add_action('admin_menu', 'related_post_options_box');

function related_post_options_box() {
add_meta_box('post_info', 'Related Information', 'related_post_info', 'related', 'side', 'high');
}

function related_post_info() {
global $post;
/* List the posts*/
    query_posts( array('post_type' => array( 'related', 'produktkrav', 'filtreringskriterie' )));
        echo '<select name="related" id="related" multiple>'.
         '<option value="" selected="selected">Select a post</option>';
        while ( have_posts() ) : the_post();
echo '<option value="';
        the_permalink();
        echo '">';
        the_title();
        echo '</option>';
    endwhile;

    echo '</select>';
}
I would like to use the function save_post but I don´t know how. Of course, the dropdown has to allow multiple selection.

No comments:

Post a Comment