Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to create a wordpress plugin that adds additional input fields to the Write/Edit page
    primarykey
    data
    text
    <p>I am writing a plugin that requires additional information from the use when they create a post. I need a text box that they will enter a number that can have decimals and a drop down box that will give a few options. I also need this data to be saved with the rest of the post data in the wordpress DB. Can someone give me some help with this?</p> <p>P.S. i will later need to add an area to the post itself when displayed that shows a piece of data calculated from the plugin but first things first. </p> <p>EDIT: i got the first part done but now i can't get the new fields to save data with the post, here is my code.</p> <pre><code>&lt;?php /* Plugin Name: Column Height Calculator Plugin URI: # Description: calculates the height of the column Version: 0.1 Author: Ben Crawford Author URI: */ add_action('admin_menu', 'my_post_options_box'); function my_post_options_box() { add_meta_box('post_info', 'Column Height Info', 'custom_post_info', 'post', 'side', 'high'); } //Adds the actual option box function custom_post_info() { global $post; ?&gt; &lt;fieldset id="mycustom-div"&gt; &lt;div&gt; &lt;p&gt; &lt;label for="column_type" &gt;Column Type:&lt;/label&gt; &lt;br /&gt; &lt;select name="column_type" id="column_type"&gt; &lt;option value="JBC"&gt;Justified Body Copy&lt;/option&gt; &lt;option value="LRC"&gt;Left Raggid Copy&lt;/option&gt; &lt;/select&gt; &lt;br /&gt; &lt;br /&gt; &lt;label for="header_size"&gt;Header Size:&lt;/label&gt; &lt;br /&gt; &lt;input type="text" name="header_size" id="header_size" value="&lt;?php echo get_post_meta($post-&gt;ID, 'header_size', true); ?&gt;"&gt; &lt;/p&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;?php } add_action('save_post', 'custom_add_save'); function custom_add_save($postID){ // called after a post or page is saved if($parent_id = wp_is_post_revision($postID)) { $postID = $parent_id; } if ($_POST['column_type']) { update_custom_meta($postID, $_POST['column_type'], 'column_type'); } if ($_POST['header_size']) { update_custom_meta($postID, $_POST['header_size'], 'header_size'); } } function update_custom_meta($postID, $newvalue, $field_name) { // To create new meta if(!get_post_meta($postID, $field_name)){ add_post_meta($postID, $field_name, $newvalue); }else{ // or to update existing meta update_post_meta($postID, $field_name, $newvalue); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload