Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Php 从自定义发布类型下拉列表中选择的发布日期发布到ajax_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Php 从自定义发布类型下拉列表中选择的发布日期发布到ajax

Php 从自定义发布类型下拉列表中选择的发布日期发布到ajax,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我有一个自定义帖子类型的日期下拉列表。所以所有发表文章的日期都显示了。。我需要将此信息发送到我的ajax页面。我该怎么做 这是我获取帖子日期的代码 <select id="date"> <?php $dates = array(); $argez = (array( 'post_type' => 'latest_message')); query_posts( $argez ); if (have_posts()) : while (have_posts()) :

我有一个自定义帖子类型的日期下拉列表。所以所有发表文章的日期都显示了。。我需要将此信息发送到我的ajax页面。我该怎么做 这是我获取帖子日期的代码

<select id="date">
<?php
$dates = array();
$argez = (array( 'post_type' => 'latest_message'));
query_posts( $argez );
  if (have_posts())  : while (have_posts()) : the_post(); 
    $dates[] = get_the_date();
    $dates = array_unique($dates);
    print_r($datesun);

   endwhile; 
   foreach($dates as $date) {
    echo '<option value="' . $date . '">' . $date .'</option> ';
  }
 endif;
?>
</select>
我如何发布我的日期,以便当我点击日期时,它从所选主题和相应日期中获取信息,并给出结果。这是激活ajax的函数

jQuery('. .series-topic #cat').on('change',function() {
    var selectedTopic = jQuery('.series-topic #cat').val();
    var selectedDate = jQuery('.series-date #date').val();
    console.log(selectedTopic);
    console.log(selectedDate);
    jQuery.ajax({
        type: 'post',
        url: '/ajax',
        data: {
            topic: selectedTopic,
            date: selectedDate
        },
         success:function(data) {
             if(data) {  
                 jQuery('.-hold').html(data);
            } else {}
        }
    });
});

如何让我的日期使用此

这应该适用于处理发布日期和根据日期条件查询帖子。(注意:此代码未经测试,因此请原谅任何打字错误)

而且--我想你是在问,即使在你的日期下拉列表中,如何也附加到更改。要进行此更改,请执行以下操作:

jQuery('. .series-topic #cat').on('change',function() {
致:

jQuery('. .series-topic #cat').on('change',function() {
    var selectedTopic = jQuery('.series-topic #cat').val();
    var selectedDate = jQuery('.series-date #date').val();
    console.log(selectedTopic);
    console.log(selectedDate);
    jQuery.ajax({
        type: 'post',
        url: '/ajax',
        data: {
            topic: selectedTopic,
            date: selectedDate
        },
         success:function(data) {
             if(data) {  
                 jQuery('.-hold').html(data);
            } else {}
        }
    });
});
if($_POST['date'] != null){
    $date_parsed = strtotime($_POST['date']);
    $args = array(
        'date_query' => array(
        array(
            'year'  => date('Y',$date_parsed),
            'month' => date('m',$date_parsed),
            'day'   => date('d',$date_parsed),
        ),
        ),
    );
    $query = new WP_Query( $args ); 

    while ($query->have_posts()){ 
         $query->the_post(); 
         //DO WHATEVER YOU WANT WITH EACH POST
    }
}
jQuery('. .series-topic #cat').on('change',function() {
jQuery('. .series-topic #cat, #date').on('change',function() {