Query custom posts by date in a dropdown list and link to a ajax call

I have a loop that shows the dates from the custom post type but it shows every date for every post item instead of just one date for all posts posted on that date.

<ul class="taxonomy-drops series-topic one-fifth">

    <?php
    $args = array(   'post_type' => 'latest_message', 'orderby' => 'date', );
    $myposts = get_posts( $args );

    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    <?php $testn=get_the_date();?>
        <li id="categories">
            <?php echo $testn; ?>
        </li>
    <?php endforeach; 
    wp_reset_postdata();?>
</ul>

This is my ajax page code. I basically need to click on a series, speakers name, topic and date and t needs to bring up all the posts by that person on the date. The ajax i working for the speaker etc now I need to get the date to work together with the the other dropdowns
global $post, $wpdb;

Read More
if ($_POST["series"]!=0 ) {
    $series = array($_POST['series']);
} else {
    $series = get_terms( 'series', array('fields' => 'ids') );
    //$series = array(implode(', ',$series));
}

if ($_POST["speaker"]!=0 ) {
    $speaker = array($_POST["speaker"]);
} else {
    $speaker = get_terms( 'speaker', array('fields' => 'ids') );
    //$speaker = array(implode(', ',$speaker));
}

if ($_POST["topic"]!=0 ) {
    $topic = array($_POST["topic"]);
} else {
     $topic = get_terms( 'topic', array('fields' => 'ids') );
     //$topic = array(implode(', ',$topic));
}

wp_reset_query();
$myquery['tax_query'] = array(
    array(
        'taxonomy' => 'series',
        'terms' => $series,
        'field' => 'id'
    ),
    array(
        'taxonomy' => 'speaker',
        'terms' => $speaker,
        'field' => 'id',
    ),
    array(
        'taxonomy' => 'topic',
        'terms' => $topic,
        'field' => 'id',
    )
);

This is my jQuery to activate my ajax. I need to be able to add the date to this code to get it working simultaneously with the the other dropdown lists categories..

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

Ok Got the dates to work using this

<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>

How do I now add this to my ajax using something similar to this

if ($_POST["topic"]!=0 ) {
    $topic = array($_POST["topic"]);
} else {
    $topic = get_terms( 'topic', array('fields' => 'ids') );
    //$topic = array(implode(', ',$topic));
}

array(
    'taxonomy' => 'topic',
    'terms' => $topic,
    'field' => 'id',
)

Related posts

Leave a Reply