Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 如何让Wordpress post filter(misha_filter_函数)过滤标签关联的CPT类别_Php_Jquery_Wordpress_Filter - Fatal编程技术网

Php 如何让Wordpress post filter(misha_filter_函数)过滤标签关联的CPT类别

Php 如何让Wordpress post filter(misha_filter_函数)过滤标签关联的CPT类别,php,jquery,wordpress,filter,Php,Jquery,Wordpress,Filter,为清晰起见进行了编辑: 我正在使用misha_filter_函数from:来过滤帖子 初始数组通过位置和季节(使用ACF制作)标记显示正确的帖子。但第二个数组出现了一些奇怪的情况,因为当我单击下拉选择按类别对帖子进行排序时,它会过滤帖子类型中的所有帖子,并有效地忽略“tag”=>$value 我对Wordpress PHP和JS比较陌生,所以我的Google Fu并没有太大帮助,因为我真的不知道搜索什么。任何帮助都将不胜感激。谢谢 以下是筛选代码: <?php add_action('wp

为清晰起见进行了编辑:

我正在使用misha_filter_函数from:来过滤帖子

初始数组通过位置和季节(使用ACF制作)标记显示正确的帖子。但第二个数组出现了一些奇怪的情况,因为当我单击下拉选择按类别对帖子进行排序时,它会过滤帖子类型中的所有帖子,并有效地忽略“tag”=>$value

我对Wordpress PHP和JS比较陌生,所以我的Google Fu并没有太大帮助,因为我真的不知道搜索什么。任何帮助都将不胜感激。谢谢

以下是筛选代码:

<?php
add_action('wp_ajax_myfilter', 'misha_filter_function'); // 
wp_ajax_{ACTION HERE}
add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');

function misha_filter_function()
{
$value = get_field('location_and_season');

$args = array(
    'post_type' => 'shows',
    'tag' => $value,
    'posts_per_page' => - 1, // show all posts.
    'orderby' => 'name', // we will sort posts by name
    'order' => 'ASC'
    //$_POST['name'] // ASC or DESC

);

// for taxonomies / categories
// IMPORTANT! Adding && !empty( $_POST['categoryfilter'] ) fixes the no posts found for All Categories
if (isset($_POST['categoryfilter']) && 
!empty($_POST['categoryfilter'])) $args['tax_query'] = array(
    array(
        'taxonomy' => 'category',
        'field' => 'id',
        'terms' => $_POST['categoryfilter']
    )
);

$query = new WP_Query($args);
// The Query
query_posts($args);

// The Loop
while (have_posts()):
    the_post(); ?>

以下是前端下拉代码:

<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" 
method="POST" id="filter" style="float:right; margin-right: 15px;">

<?php
if ($terms = get_terms(array(
'taxonomy' => 'category',
'orderby' => 'name'
))):

echo '<select name="categoryfilter"><option id="refresh" value="all" 
class="dropdown-select">All Topics...</option>';

foreach ($terms as $term):
    echo '<option value="' . $term->term_id . '">' . $term->name . 
   '</option>'; 

endforeach;
echo '</select>';
endif;
?>
<div class="processing" style="height:30px;"></div>

<input type="hidden" name="action" value="myfilter">
</form>

我没有看到任何真正调用php函数的东西。Wordpress ajax调用需要在数据中执行操作

$.ajax({
    url: filter.attr('action'),
    type: filter.attr('method'), // POST
    data: {
         action: 'misha_filter_function',
         categoryfilter:  $(select['name ="categoryfilter"]').val()
    },
    beforeSend: function (xhr) {
        filter.find('.processing').html('<img src="spinner.gif" class="spinner">'); // changing the button label
    },
    success: function (data) {
        filter.find('.processing').text(''); // changing the button label back
        $('#response').html(data); // insert data
    }, 
    failure: function(response){
        console.log(response); //Debug only
    }
});
$.ajax({
url:filter.attr('action'),
类型:filter.attr('method'),//POST
数据:{
措施:“misha_过滤器_函数”,
categoryfilter:$(选择['name=“categoryfilter”]”)。val()
},
发送前:函数(xhr){
filter.find('.processing').html('');//更改按钮标签
},
成功:功能(数据){
filter.find('.processing').text('');//重新更改按钮标签
$('#response').html(数据);//插入数据
}, 
故障:功能(响应){
console.log(响应);//仅调试
}
});

另外,您是否将js脚本与?

一起排队?谢谢您的回复。我认为我的入门主题中有一个内置的东西,即调用ajax。我的js文件使用的是标准的“wp_enqueue_脚本”,但似乎一切正常。当我使用该过滤器按类别过滤帖子时,它可以正常工作,但现在我需要它只包含带有我在这里定义的标记的帖子:“tag”=>$value,。
$.ajax({
    url: filter.attr('action'),
    type: filter.attr('method'), // POST
    data: {
         action: 'misha_filter_function',
         categoryfilter:  $(select['name ="categoryfilter"]').val()
    },
    beforeSend: function (xhr) {
        filter.find('.processing').html('<img src="spinner.gif" class="spinner">'); // changing the button label
    },
    success: function (data) {
        filter.find('.processing').text(''); // changing the button label back
        $('#response').html(data); // insert data
    }, 
    failure: function(response){
        console.log(response); //Debug only
    }
});