Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wordpress通过Ajax每周获得帖子_Javascript_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Javascript Wordpress通过Ajax每周获得帖子

Javascript Wordpress通过Ajax每周获得帖子,javascript,php,jquery,ajax,wordpress,Javascript,Php,Jquery,Ajax,Wordpress,我根据“事件\日期”的自定义字段按周显示事件(自定义帖子类型)。我已经开始工作了。它所做的是获取当前周的开始和结束,并返回该时间段内发生的事件。我需要能够做的是单击下一个或上一个按钮并基于该周更新事件(事件应通过Ajax更新) 这是我的jqueryclick函数。它只需点击“get events.php”页面并将数据附加到div $('.next-week').click(function(e) { e.preventDefault(); $.ajax({ url:

我根据“事件\日期”的自定义字段按周显示事件(自定义帖子类型)。我已经开始工作了。它所做的是获取当前周的开始和结束,并返回该时间段内发生的事件。我需要能够做的是单击下一个或上一个按钮并基于该周更新事件(事件应通过Ajax更新)

这是我的jqueryclick函数。它只需点击“get events.php”页面并将数据附加到div

$('.next-week').click(function(e) {
    e.preventDefault();
    $.ajax({
      url: "http://gwsb-website/wp-content/themes/gwsb/get-events.php",
      cache: false
    }).done(function( html ) {
    $('.events-listing').html( html );
  });
});
下面是“get events.php”中的php

<!-- language: lang-php -->
<?php

define('WP_USE_THEMES', false);
require_once('../../../wp-load.php');

// Variables
$day = date('w');
$weekStart = date('Ymd', strtotime('monday this week'));
$weekEnd = date('Ymd', strtotime('sunday this week'));
$currentHeader = '';

query_posts(array(
    'post_type' => 'event',
    'posts_per_page' => -1,
    'meta_key'      => 'event_date',
  'orderby' => 'meta_value_num',
  'order' => 'ASC',
    'meta_query' => array(
        array(
            'key' => 'event_date',
            'value' => array( $weekStart, $weekEnd ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'
        )
    )
));
?>

<?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    <?php 
    $tempDate = get_post_meta( get_the_ID(), 'event_date', true );
    if ( $tempDate != $currentHeader ) : $currentHeader = $tempDate; ?>
    <h3 class="event-date-header"><?php $date = DateTime::createFromFormat('Ymd', $currentHeader); echo $date->format('l, F d, Y'); ?></h3>
    <?php endif; ?>

    <div class="event<?php echo the_subcategory_class(); ?>">
        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
        <p><?php $content = get_the_content(); echo wp_trim_words( $content , '20' ); ?></p>

        <div class="event-meta">
        <?php if (get_field('start_time')) : ?>
            <span><?php the_field('start_time'); ?></span>
        <?php endif; ?>

        <?php if (get_field('end_time')) : ?>
            <span> - </span><span><?php the_field('end_time'); ?></span>
        <?php endif; ?> 

        <?php if (get_field('location')) : ?>
            <span class="dot">&bull;</span><span><?php the_field('location'); ?></span>
        <?php endif; ?>
        </div><!--  .event-meta -->
    </div><!-- .event -->
<?php endwhile; ?>

<?php wp_reset_query(); ?>


你需要下周的活动,还是你建议分页?是的,我需要下周或前一周的活动,具体取决于用户单击的链接。您将能够在一年中的所有52周中循环。您可以传递prev和next的prev next week days值,并通过url将其作为GET传递