Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am at a loss here. I have a custom meta field blser_date where the client can use the date picker. The meta field is setup in a meta box array (this may be an issue b/c of the key?) Here is the full code for this meta box & its fields:

function add_blser_meta_box() {
add_meta_box(
    'blser_meta_box',
    'Service Information',
    'show_blser_meta_box',
    'obituaries',
    'normal',
    'default');
}
add_action('add_meta_boxes', 'add_blser_meta_box');

$prefix = 'blser_';
$blser_meta_fields = array(
array(
    'label' => 'Date',
    'desc'  => '',
    'id'    => $prefix.'date',
    'type'  => 'date'
),

array(
    'label'=> 'Time',
    'desc'  => '',
    'id'    => $prefix.'time',
    'type'  => 'text'
),

array(
    'label'=> 'Location Name',
    'desc'  => '',
    'id'    => $prefix.'text',
    'type'  => 'text'
),

array(
    'label'=> 'Location Address',
    'desc'  => '',
    'id'    => $prefix.'address',
    'type'  => 'textarea'
),

array(
    'label'=> 'Details',
    'desc'  => '',
    'id'    => $prefix.'textarea',
    'type'  => 'textarea'
    )
);

function show_blser_meta_box() {
global $blser_meta_fields, $post;

echo '<input type="hidden" name="blser_meta_box_nonce"           value="'.wp_create_nonce(basename(__FILE__)).'" />';


echo '<table class="form-table">';
foreach ($blser_meta_fields as $field) {
    // get value of this field if it exists for this post
    $meta = get_post_meta($post->ID, $field['id'], true);

    echo '<tr>
            <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
            <td>';
            switch($field['type']) {


                // Date
                case 'date':
                    echo '<input type="text" class="datepicker" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
                        <br /><span class="description">'.$field['desc'].'</span>';
                break;


                // Time
                case "time":
                    echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
                        <br /><span class="description">'.$field['desc'].'</span>';
                break;

                // location name
                case 'text':
                    echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
                        <br /><span class="description">'.$field['desc'].'</span>';
                break;

                // address
                case 'address':
                    echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
                        <br /><span class="description">'.$field['desc'].'</span>';
                break;

                // details
                case 'textarea':
                    echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
                        <br /><span class="description">'.$field['desc'].'</span>';
                break;

            } //end switch
    echo '</td></tr>';
} // end foreach
echo '</table>'; // end table
}

// Save the Data
function save_blser_meta($post_id) {
global $blser_meta_fields;

// verify nonce
if (!wp_verify_nonce($_POST['blser_meta_box_nonce'], basename(__FILE__))) 
    return $post_id;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
    return $post_id;
// check permissions
if ('page' == $_POST['post_type']) {
    if (!current_user_can('edit_page', $post_id))
        return $post_id;
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
}

// loop through fields and save the data
foreach ($blser_meta_fields as $field) {
    $old = get_post_meta($post_id, $field['id'], true);
    $new = $_POST[$field['id']];
    if ($new && $new != $old) {
        update_post_meta($post_id, $field['id'], $new);
    } elseif ('' == $new && $old) {
        delete_post_meta($post_id, $field['id'], $old);
    }
} // end foreach
}
add_action('save_post', 'save_blser_meta');
?>

If the issue that blser_date needs its own key, how and where do I create this?

I am trying to list post within different tabs on the site. One tab will be for Current Services (dates that are today and/or upcoming). The second tab will be for Recent Services (dates that have passed todays date - In descending order with in the last 30 days of todays date). Here is the code for the tabs as of right now (I am sure it is trashed up by this time):

<ul class="nav nav-tabs">
<li class="active"><a href="#current-services" data-toggle="tab">Current Services</a>            </li>
  <li><a href="#recent-services" data-toggle="tab">Recent Services</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane fade in active" id="current-services">

    <?php
    $today = date('Y-m-d', strtotime('+30 days'));
    $args = array( 'post_type' => 'obituaries', 'meta_key' => 'blser_date' , 'posts_per_page' => '10',  'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_compare' => '>=');

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="obits_list"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?        php the_title_attribute(); ?>"><?php the_post_thumbnail( ); ?></a>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php     the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<p><?php echo get_post_meta( get_the_ID(), 'bldob_bdate', true ); ?> ~ <?php echo     get_post_meta( get_the_ID(), 'bldob_ddate', true ); ?></p>
<p>Service: <?php echo get_post_meta( get_the_ID(), 'blser_date', true ); ?></p>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
  </div>

  <div class="tab-pane fade" id="recent-services">
    <?php
    $today = date('Y-m-d', strtotime('-30 days'));
        $the_query = new WP_Query( array(
      'post_type' => 'obituaries',
      'posts_per_page' => 10,
      'meta_key' => 'blser_date',
      'orderby' => 'meta_value',
      'order' => 'DESC',
      'meta_query' => array(
      array(
        'key' => 'blser_date',
        'value' => $today,
        'compare' => '<',
        'type' => 'DATE'
      ))
    ));

while (have_posts()) : the_post(); ?>

<div class="obits_list"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?    php the_title_attribute(); ?>"><?php the_post_thumbnail( ); ?></a>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php     the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<p><?php echo get_post_meta( get_the_ID(), 'bldob_bdate', true ); ?> ~ <?php echo     get_post_meta( get_the_ID(), 'bldob_ddate', true ); ?></p>
<p>Service: <?php echo get_post_meta( get_the_ID(), 'blser_date', true ); ?></p>
</div>

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>   
  </div>
</div>

Here is a link to view the actual page if it will help at all: page

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.