I have a custom post type for a simple schedule list and using the meta box plugin i have two meta boxes assigned to custom post type. 1 for an image and 1 for an array of date times .
In my functions.php file I have created a shortcode to retrieve and display the info. HOWEVER it is only showing the post once and where i display the date time it says "array". I want to show the post 3 times based on the fact that I have stored 3 date times with the meta box. I'm not sure how to adjust my query or loop to make the post show 3 times in order of date. Below is my shortcode from my functions.php file. Any help would be greatly appreciated.
// SCHEDULE LIST
add_shortcode( 'schedule', 'display_schedule' );
function display_schedule(){
global $paged;
$args = array(
'post_type' => 'tbschedule',
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 10
);
$string = '';
$query = new WP_Query( $args );
if( $query->have_posts() ){
$string .= '<span class="schedules">';
while( $query->have_posts() ){
$query->the_post();
$schedule_image = "";
$schedule_image_url = "";
$images = rwmb_meta( 'tbf_scheduleimage', 'type=image&size=full');
foreach ( $images as $image ){
$schedule_image = "<img src='{$image['url']}' class='first' alt='{$image['alt']}' title='{$image['title']}' />";
$schedule_image_url = $image['url'];
}
if($schedule_image_url == ""){
$string .= '<div class="schedule"><span class="scheduletitle"><a href="'.get_permalink().'">' . get_the_title() . '<span class="scheduleDate">schedule date: '.rwmb_meta('tbf_scheduledatetime').'</span></a></span></div>';
}else{
$string .= '<div class="schedule">
<a href="'.get_permalink().'"><span class="scheduleimage" style="background-image: url('. $schedule_image_url .');background-repeat: no-repeat;background-position: center center;background-size: contain;"></span></a>
<span class="newstitle"><p style="height: 122px;"><a href="'.get_permalink().'">' . get_the_title() . '<span class="scheduleDate">schedule date: '.rwmb_meta('tbf_scheduledatetime').'</span></a></p></span>
</div>';
}
}
}
$string .= '</span>';
// Paging
$q = $query;
$big = 999999999; // need an unlikely integer
$string .= '<p> </p>'.paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $q->max_num_pages //$q is your custom query
) );
wp_reset_postdata();
return $string;
}
// END SCHEDULE LIST