Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.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/1/php/247.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 带有WP_查询的Ajax后期过滤器只对Category触发一次_Javascript_Php_Jquery_Ajax_Wordpress - Fatal编程技术网

Javascript 带有WP_查询的Ajax后期过滤器只对Category触发一次

Javascript 带有WP_查询的Ajax后期过滤器只对Category触发一次,javascript,php,jquery,ajax,wordpress,Javascript,Php,Jquery,Ajax,Wordpress,我有一个模仿的ajax后过滤器。我让它大部分按预期工作,但我希望能够按类别筛选讲座(它实际上是一个子类别,但我不知道这是否有任何区别) 我为speaker和最新的讲座设置了过滤器,这些过滤器工作正常,但当我尝试运行Series filter(带有elseif(isset($\u POST['Series\u name'])的部分)时,我没有得到任何响应。如果先尝试运行串联过滤器,它将触发一次,但随后不会响应。如果我先尝试运行任何其他过滤器,它们都可以正常工作,但是串联过滤器根本不会启动。我想我的

我有一个模仿的ajax后过滤器。我让它大部分按预期工作,但我希望能够按类别筛选讲座(它实际上是一个子类别,但我不知道这是否有任何区别)

我为speaker和最新的讲座设置了过滤器,这些过滤器工作正常,但当我尝试运行Series filter(带有elseif(isset($\u POST['Series\u name'])的部分)时,我没有得到任何响应。如果先尝试运行串联过滤器,它将触发一次,但随后不会响应。如果我先尝试运行任何其他过滤器,它们都可以正常工作,但是串联过滤器根本不会启动。我想我的问题是,当设置$\u POST['series\u name']时,如何处理WP\u查询的$args

如果您有任何建议,我们将不胜感激,谢谢

以下是我的php:
function lectures_filter_function(){
$i = 1;
$args = array( 
    'post_type' => 'lectures',
    'orderby' => 'meta_value',
    'meta_key' => 'lecture_date',
    'order' => 'DESC'       
); 

if( isset( $_POST['speaker'] ) ) 
{
    $args['meta_query'][] = array(
        'key' => 'speaker',
        'value' => $_POST['speaker'],
    );
} 
elseif( isset( $_POST['series_name'] ) ) 
{
    //*This is how I wanted to code it but it didn't work at all*
    // $args['tax_query'] = array(
    //      array(
    //          'taxonomy' => 'category',
    //          'value' => 'category_name',
    //          'terms' => $_POST['series_name']
    //      )
    //  );

    //This is how I at least got it to fire once per screen load.
    $args = array(
                'category_name' => $_POST['series_name'],
                'post_type' => 'lectures',
                'orderby' => 'meta_value',
                'meta_key' => 'lecture_date',
                'order' => 'DESC'                   
        );      
}


    $the_query = new WP_Query( $args );
    $postlist = $the_query->post_count;

    // The Query

    // The Loop
    if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
            $the_query->the_post();

            // print_r($the_query);

            if($i % 2 == 1){
                echo '<div class="row">';
            }   
        ?>      

        <div class="large-6 columns lecture-tile">
            <div class="lecture-overlay-container">
                <a href="<?php the_permalink();?>">
                    <div class="lecture-tile-overlay"></div>
                    <?php the_post_thumbnail('full');?>
                    <div class="lecture-tile-info">
                        <h3><?php the_title();?></h3>

<?php 
    $current_id = get_the_id();
    $lecture_type = get_post_meta($current_id, 'lecture_type', true);
    if($lecture_type == "Single"){
        $lecture_descriptor = "lecture";
    }elseif ($lecture_type == 'Series') {
        $series_name = get_post_meta($current_id, 'series_name', true);
        $lecture_descriptor = $series_name;
    }elseif ($lecture_type == 'Event') {
        $event_name = get_post_meta($current_id, 'event_name', true);
        $lecture_descriptor = $event_name;
    }           
?>                              
                        <p><?php echo $lecture_descriptor; ?></p>                           
                    </div>
                </a>
            </div>
        </div>  

        <?php
                if($i % 2 == 0 || $i == $num_posts){
                    echo '</div>';
                }
                $i++;
        }
        /* Restore original Post Data */
        wp_reset_postdata();
    } else {
        // no posts found
        echo "No matching lectures found...";
    }
die();
试试这个

$args = array(
'post_type' => 'post',
'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'movie_genre',
        'field'    => 'slug',
        'terms'    => array( 'action', 'comedy' ),
    ),
    array(
        'taxonomy' => 'actor',
        'field'    => 'term_id',
        'terms'    => array( 103, 115, 206 ),
        'operator' => 'NOT IN',
    ),
),
);
$query = new WP_Query( $args );
试试这个

$args = array(
'post_type' => 'post',
'tax_query' => array(
    'relation' => 'AND',
    array(
        'taxonomy' => 'movie_genre',
        'field'    => 'slug',
        'terms'    => array( 'action', 'comedy' ),
    ),
    array(
        'taxonomy' => 'actor',
        'field'    => 'term_id',
        'terms'    => array( 103, 115, 206 ),
        'operator' => 'NOT IN',
    ),
),
);
$query = new WP_Query( $args );

恐怕不行。根据您的示例,我提出了
$terms=strtolower($\u POST['series\u name']);$args=array('post_-type'=>'categories'、'orderby'=>'meta_-value'、'meta_-key'=>'categority'、'terms'=>'DESC'、'tax_-query'=>数组(数组('taxonomy'=>'category'、'field'=>'slug'、'terms'=>'terms',),)和以前一样,每当我再次尝试使用series时,ajax启动一次,然后就坏了,或者在没有series过滤器的情况下工作得很好。我想问题可能出在我的表单上,但我从speakers筛选器复制了格式。请尝试使用此
$category=get\u term\u by('name'、'news'、'category'),恐怕它不起作用。根据您的示例,我提出了
$terms=strtolower($\u POST['series\u name']);$args=array('post_-type'=>'categories'、'orderby'=>'meta_-value'、'meta_-key'=>'categority'、'terms'=>'DESC'、'tax_-query'=>数组(数组('taxonomy'=>'category'、'field'=>'slug'、'terms'=>'terms',),)和以前一样,每当我再次尝试使用series时,ajax启动一次,然后就坏了,或者在没有series过滤器的情况下工作得很好。我想问题可能出在我的表单上,但我从speakers筛选器中复制了格式。请尝试使用('name','news','category')获取术语