Exibir post de acordo com horário real
Olá pessoal, preciso exibir o post de acordo com o horário inserido na edição. Seria algo como: "se horário real é igual ou maior ao inicial e horário real é menor ou igual ao final, exibir post referente a determinado horário." Porque da forma que está, ele exibe todos os posts cadastrados. :/ Segue o código:
<?php
add_shortcode('show_schedule', 'show_schedule');
$days = array('sun'=>'Sunday','mon'=>'Monday','tue'=>'Tuesday','wed'=>'Wednesday','thu'=>'Thursday','fri'=>'Friday','sat'=>'Saturday');
//Register Schdule Post Type
add_action( 'init', 'register_my_dj_schedule' );
function register_my_dj_schedule() {
$labels = array(
'name' => _x( 'Dj Schedule', 'dj_schedule' ),
'singular_name' => _x( 'Dj Schedule', 'dj_schedule' ),
'add_new' => _x( 'Add New', 'dj_schedule' ),
'add_new_item' => _x( 'Add New Schedule', 'dj_schedule' ),
'edit_item' => _x( 'Edit Dj Schedule', 'dj_schedule' ),
'new_item' => _x( 'New Dj Schedule', 'dj_schedule' ),
'view_item' => _x( 'View Dj Schedule', 'dj_schedule' ),
'search_items' => _x( 'Search Dj Schedule', 'dj_schedule' ),
'not_found' => _x( 'No dj schedule found', 'dj_schedule' ),
'not_found_in_trash' => _x( 'No dj schedule found in Trash', 'dj_schedule' ),
'parent_item_colon' => _x( 'Parent Dj Schedule:', 'dj_schedule' ),
'menu_name' => _x( 'Dj Schedule', 'dj_schedule' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'WordPress DJ Schedule',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'taxonomies' => array( 'category', 'dj_schedule' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'dj_schedule', $args );
}
//Register DJs Post Type
add_action( 'init', 'register_my_radios_djs' );
function register_my_radios_djs() {
$labels = array(
'name' => _x( 'Radio Djs', 'radios_djs' ),
'singular_name' => _x( 'Radio Dj', 'radios_djs' ),
'add_new' => _x( 'Add New', 'radios_djs' ),
'add_new_item' => _x( 'Add New Dj', 'radios_djs' ),
'edit_item' => _x( 'Edit Dj', 'radios_djs' ),
'new_item' => _x( 'New Dj', 'radios_djs' ),
'view_item' => _x( 'View Dj', 'radios_djs' ),
'search_items' => _x( 'Search Dj', 'radios_djs' ),
'not_found' => _x( 'No dj found', 'radios_djs' ),
'not_found_in_trash' => _x( 'No dj found in Trash', 'radios_djs' ),
'parent_item_colon' => _x( 'Parent Dj:', 'radios_djs' ),
'menu_name' => _x( 'Radio Djs', 'radios_djs' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'WordPress Radio DJS',
'supports' => array( 'title', 'editor', 'thumbnail' ),
'taxonomies' => array( 'category', 'radios_djs' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'radios_djs', $args );
}
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true );
add_image_size( 'dj-pic', 260, 160 );
}
add_action( 'add_meta_boxes', 'rschedule_box' );
add_action( 'save_post', 'dj_schedule_save_postdata' );
function rschedule_box() {
add_meta_box(
'time_slot_id',
__( 'Time Slots', 'time_slot_text' ),
'radio_time_slots',
'dj_schedule'
);
add_meta_box(
'dj_select_id',
__( 'Select DJ', 'dj_select_text' ),
'radio_get_dj_select_box',
'dj_schedule',
'side'
);
}
function radio_get_dj_select_box($post){
wp_nonce_field( 'radio_schedule', 'schedule_noncename' );
echo '<label for="dj_id">';
_e("DJ/Host", 'dj_id' );
echo '</label> ';
$args = array( 'post_type' => 'radios_djs');
$loop = new WP_Query( $args );
echo '<select name="dj_id" id="dj_id">';
foreach($loop->posts as $dj):
if($dj->ID == get_post_meta( $post->ID, 'dj_id', true ))
{
$select = 'selected';
}else{
$select = '';
}
echo '<option value="'.$dj->ID.'" '.$select.'>'.$dj->post_title.'</option>';
endforeach;
echo '</select>';
}
$days = array('sun'=>'Sunday','mon'=>'Monday','tue'=>'Tuesday','wed'=>'Wednesday','thu'=>'Thursday','fri'=>'Friday','sat'=>'Saturday');
function schedule_time_select($selected){
$start = 8*60+0;
$end = 24*60+0;
echo '<option value="0">N/A</option>'; //Default Value
for($time = $start; $time<=$end; $time += 15){
$minute = $time%60;
$hour = ($time-$minute)/60;
if($selected == sprintf('%02d:%02d', $hour, $minute))
{
$select = 'selected';
}else{
$select = '';
}
echo '<option value='.sprintf('%02d:%02d', $hour, $minute).' '.$select.'>'.sprintf('%02d:%02d', $hour, $minute).'</option>';
}
}/ Prints the box content /
function radio_time_slots($post) {
global $days;
// Use nonce for verification
wp_nonce_field( 'radio_schedule', 'schedule_noncename' );
foreach($days as $key=>$value){
$selected_start = get_post_meta( $post->ID, 'schdule_dj-start-'.$key, true ); //Start Time
$selected_end = get_post_meta( $post->ID, 'schdule_dj-end-'.$key, true ); //End Time
echo '<strong>'.$value.'</strong><br />';
echo '<label for="schdule_dj-start-'.$key.'">';
_e("Start", 'schdule_dj-start-'.$key );
echo '</label> ';
echo '<select name="schdule_dj-start-'.$key.'" id="schdule_dj-start-'.$key.'">';
schedule_time_select($selected_start);
echo '</select>';
echo '<label for="schdule_dj-end-'.$key.'">';
_e("End", 'schdule_dj-end-'.$key );
echo '</label> ';
echo '<select name="schdule_dj-end-'.$key.'" id="schdule_dj-end-'.$key.'">';
schedule_time_select($selected_end);
echo '</select>';
echo '<br />';
}
}
//Save Meta Data
function dj_schedule_save_postdata( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !wp_verify_nonce( $_POST['schedule_noncename'], 'radio_schedule' ) )
return;
if ( 'page' == $_POST['post_type'] )
{
if ( !current_user_can( 'edit_page', $post_id ) )
return;
}
else
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
if( isset( $_POST['dj_id'] ) ){
update_post_meta( $post_id,'dj_id', esc_attr( $_POST['dj_id'] ) );
}
global $days;
foreach($days as $key=>$value){
if( isset( $_POST['schdule_dj-start-'.$key] ) ){
update_post_meta( $post_id,'schdule_dj-start-'.$key, esc_attr( $_POST['schdule_dj-start-'.$key] ) );
}
if( isset( $_POST['schdule_dj-end-'.$key] ) ){
update_post_meta( $post_id,'schdule_dj-end-'.$key, esc_attr( $_POST['schdule_dj-end-'.$key] ) );
}
}
}
function show_schedule() {
global $days;
$html='';
$html.= '<div>';
$args = array( 'post_type' => 'dj_schedule');
$loop = new WP_Query( $args );
foreach($loop->posts as $item):
$html.= '<div class="scheduleBox">';
$html.= '<h3>'.$item->post_title.'</h3>';
$dj_id = get_post_meta($item->ID, 'dj_id', true);
$dj = get_post($dj_id);
$html.= '<div>'.$dj->post_title.'</div>';
$html.= '<div>'.get_the_post_thumbnail($dj->ID, 'dj-pic').'</div>';
foreach($days as $key=>$value){
$start = get_post_meta($item->ID, 'schdule_dj-start-'.$key, true);
$end = get_post_meta($item->ID, 'schdule_dj-end-'.$key, true);
if ( $start <> 0 )
$html.= '<div id="time">'.$value.' '.$start.'-'.$end.'</div>';
}
$html.= '</div>';
endforeach;
$html.= '<div style="clear:both;"></div>';
$html.='</div>';
return $html;
}
add_shortcode('show_schedule', 'show_schedule');Discussão (15)
Carregando comentários...