Posted By

fedek6 on 04/16/14


Tagged

php wordpress customization


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fhenderson


Option [Year] for Wordpress post


 / Published in: PHP
 

Additional option for Wordpress post (year in this case). You can get it's content in template file by: <?php>ID, 'year', true ); ?>

  1. /**
  2. * Date field
  3. *
  4. */
  5.  
  6. /**
  7. * Display the metabox
  8. */
  9. function date_custom_metabox() {
  10. global $post;
  11. $year = get_post_meta( $post->ID, 'year', true );
  12. ?>
  13. <p><label for="startdate">Rok:</label><br />
  14. <input id="startdate" size="37" name="year" class="event-date" value="<?php if( $year) { echo $year; } ?>" /></label></p>
  15. <?php
  16. }
  17.  
  18. /**
  19.  * Process the custom metabox fields
  20.  */
  21. function save_custom_date( $post_id ) {
  22. global $post;
  23.  
  24. if( $_POST ) {
  25. update_post_meta( $post->ID, 'year', $_POST['year'] );
  26. }
  27. }
  28.  
  29. // Add action hooks. Without these we are lost
  30. add_action( 'admin_init', 'add_custom_metabox' );
  31. add_action( 'save_post', 'save_custom_date' );
  32.  
  33.  
  34. /**
  35.  * Add meta box
  36.  */
  37. function add_custom_metabox() {
  38. add_meta_box( 'custom-metabox', 'Year', 'date_custom_metabox', 'post', 'normal', 'high' );
  39. }

Report this snippet  

You need to login to post a comment.