在函数内部时,WordPress查询失败

时间:2015-11-25 18:15:15

标签: wordpress

我正在尝试将ai1ec-events表连接到自定义帖子类型。我在函数之外工作但在内部失败。

这是整个功能。

session_start();
unset($_SESSION['counter']);
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 1;
} else {
$_SESSION['counter']++;
}

if (!isset($_SESSION['current'])) {
$_SESSION['current'] = strtotime(date('F j, Y'));
$_SESSION['current'] = strtotime('+1 day', $_SESSION['current']);
} else {

$_SESSION['current'] = strtotime('+1 day', $_SESSION['current']);
}


function my_ajax_pagination() {
$newDate = $_SESSION['current'];

?>



<div class="day_events <?php if ($_SESSION['counter'] == 0) {echo 'today';} elseif ($_SESSION['counter'] == 1) {echo 'tomorrow';} ?>">

<div>

<div class="day">
<?php if ( $_SESSION['counter'] == 0 ): ?><h3>Today</h3><?php elseif ($_SESSION['counter'] == 1): ?><h3>Tomorrow</h3><?php endif; ?>

<p><?php $curr = date('l', $newDate); echo $curr; ?></p>
<p><?php $curr = date('F j', $newDate); echo $curr; ?></p>
</div>

<div class="events">
<?php 
$ns_time = date('Ymd');
$two_weeks = strtotime('+13 day', $ns_time);
$stargs = array(
'post_type' => 'film',
'posts_per_page' => -1,
'meta_query' => array(
'relation'      => 'OR',
array(
'relation'  => 'AND',
array(
'key'       => 'film_start',
'compare'   => '<=',
'value'     => $ns_time,
),
array(
'key'       => 'film_end',
'compare'   => '>=',
'value'     => $ns_time,
)
),
array(
'relation'  => 'AND',
array(
'key'       => 'film_start',
'compare'   => '>=',
'value'     => $ns_time,
),
array(
'key'       => 'film_start',
'compare'   => '<=',
'value'     => $two_weeks,
)
)
),
'meta_key' => 'film_start',
'orderby' => 'film_start',
'order' => 'ASC'
);

$shows = new WP_Query($stargs);

if ($shows->have_posts()) : 
while ($shows->have_posts()) : 
$shows->the_post(); 

$showtitle = get_the_title();
$bgIMG = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '672' );
?>

<div class="entry">

<div class="img">
<a style="background-image:url(<?php echo $bgIMG[0]; ?>);" href="<?php echo get_permalink(); ?>"></a>
</div>

<div class="ticket_info">
<div class="info">
<p>
<a href="<?php echo get_permalink(); ?>"><strong><? echo $showtitle; ?></strong></a><br />
Dir. <? the_field('directed_by'); ?><br />
<? the_field('mpaa_rating'); ?> | <? the_field('running_time'); ?> min | Categories
</p>
</div>
<div class="tixs">
<p>Click showtime to buy tickets.</p>



<div class="alltimes">
<?php 
$targs = array(
'post_type' => 'ai1ec_event',
'posts_per_page' => -1,
'order' => 'ASC'
);
$today = new WP_Query($targs);

if ($today->have_posts()): 
while ($today->have_posts()): 
$today->the_post(); 

$tdate = date('F j, Y');
$fdate = strtotime($tdate);

global $ai1ec_registry;
$event = new Ai1ec_Event( $ai1ec_registry );
$event->initialize_from_id( $post-> ID );
$event_title = $event->get('post')->post_title;
$sort_date = $event->get( 'start' );
$event_url = $event->get('ticket_url');

$sort = strtotime($sort_date);
$sort_form = date('F j, Y', $sort);                        
$curr_form = date('F j, Y', $current); 
$dls = date('I');

if ( $event_title == $showtitle && $curr_form == $sort_form ) { 

if ($dls == 1) {
$time = date('g:iA',$sort - 60 * 60 * 4); 
} elseif ($dls == 0) {
$time = date('g:iA',$sort - 60 * 60 * 5); 
}

?>
<p data-sortby="<?php echo $time; ?>">
<?php echo '<a href="' . $event_url . '" target="_blank">' . $time . '</a>'; ?>
</p>

<?php } endwhile; endif; wp_reset_query(); ?>
</div>
</div>

</div>
</div>

<?php endwhile; endif; ?>

</div>

</div>

</div>
<?php die();
}

我承认我对此很陌生......这可能就是我为什么难以接受的原因,这可能就是为什么代码按原样编写的原因。

我感谢任何人都能提供的任何帮助。几乎可以打开所有输入。

感谢。

0 个答案:

没有答案