Support » Plugins and Hacks » radio button in Custom Field Template plugin

  • Hello, I’m trying to get radio buttons to work.

    This is how I get my custom field values normally:

    <?php $custom_value = get_post_meta($post->ID, 'custom_value', true);
    	if($custom_value) { ?>
                 <span class="something">something</span>
    <?php } ?>

    If the field is empty it does nothing, if there’s something it does something.

    But now I have one radio with two values: new and updated. I’m too neophyte in php to be able to write code. Should be something like this:

    <span class="
    <?php $custom_value = get_post_meta($post->ID, 'custom_value', true);
    	if($custom_value /*= updated*/) { ?>
    		updated
    	<?php elseif($custom_value /*= is new) { ?>
    		new
    	<?php else /*if it's none of these*/ { ?>
    		nothing
    <?php } ?>">

    All help appreciated 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • This works:

    <span class="
    <?php $status = get_post_custom_values("status"); ?>
    	<?php if ((isset($status[0])) && ($status[0] == "updated")) { ?>
    		updated-post
    	<?php } elseif ((isset($status[0])) && ($status[0] == "new")) { ?>
    		new-post
    	<?php } else { ?>
    		nothing-post
    	<?php } ?>
    ">

    That works great. My problem is getting it to save the meta data initially. I’ve gotten it to work with other meta data, but can’t figure out how to save the radio button values and how to code that part. Here is a custom field I have used with success:

    function code_meta(){
      global $post;
      $custom = get_post_custom($post->ID);
      $code_meta = $custom["code_meta"][0];
      ?>
      <p><label>Code:</label><br />
      <input name="code_meta" value="<?php echo $code_meta; ?>" /></p>
      <?php
    }

    And here is the code I am having problems with now:

    function valid_meta(){
      global $post;
      $custom = get_post_custom($post->ID);
      $valid_meta = $custom["valid_meta"][0];
      ?>
      <p><label>Valid or Expired?</label><br />
      <input type="radio" name="valid_meta" value="valid" /> Valid
      <input type="radio" name="valid_meta" value="expired" /> Expired</p>
      <?php
    }
    
    add_action('save_post', 'save_details');
    
    function save_details(){
      global $post;
    
      update_post_meta($post->ID, "code_meta", $_POST["code_meta"]);
      update_post_meta($post->ID, "valid_meta", $_POST["valid_meta"]);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘radio button in Custom Field Template plugin’ is closed to new replies.