我有两个下拉列表来过滤网站上的帖子。第二个下拉列表根据第一个下拉列表的选择进行填充,即:
[CATEGORY] + [SUB-CATEGORY] = SEARCH
问题是,有时第二个下拉列表不会填充,控制台显示:
POST: http://localhost/site/wp-admin/admin-ajax.php
{"html":"","error":"Permission error"}
这到底是什么意思?我该如何着手修复它?这是返回错误的代码:
add_action( \'wp_ajax_wpse158929_get_terms_for_cpt\', \'wpse158929_get_terms_for_cpt\' );
add_action( \'wp_ajax_nopriv_wpse158929_get_terms_for_cpt\', \'wpse158929_get_terms_for_cpt\' );
function wpse158929_get_terms_for_cpt() {
$ret = array( \'html\' => \'\', \'error\' => false );
if ( ! check_ajax_referer( \'wpse158929_get_terms_for_cpt_submit_\', \'nonce\', false /*die*/ ) ) {
$ret[\'error\'] = __( \'Permission error\', \'wpfm\' );
} else {
$post_type = isset( $_REQUEST[\'post_type\'] ) ? $_REQUEST[\'post_type\'] : \'\';
$taxonomy = isset( $_REQUEST[\'taxonomy\'] ) ? $_REQUEST[\'taxonomy\'] : \'\';
$current_selected = isset( $_REQUEST[\'current_selected\'] ) ? $_REQUEST[\'current_selected\'] : \'\';
if ( ! $post_type || ! $taxonomy ) {
$ret[\'error\'] = __( \'Params error\', \'wpfm\' );
} else {
global $wpdb;
$sql = $wpdb->prepare( \'SELECT t.slug FROM \' . $wpdb->terms . \' t\'
. \' JOIN \' . $wpdb->term_taxonomy . \' AS tt ON tt.term_id = t.term_id\'
. \' JOIN \' . $wpdb->term_relationships . \' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id\'
. \' JOIN \' . $wpdb->posts . \' AS p ON p.ID = tr.object_id\'
. \' WHERE tt.taxonomy = %s AND p.post_type = %s AND p.post_status = %s\'
. \' GROUP BY t.slug\'
, $taxonomy, $post_type, \'publish\' );
$include = $wpdb->get_col($sql);
$ret[\'html\'] = preg_replace( \'/<\\/?select[^>]*>/\', \'\', my_dropdown_categories( $taxonomy, $current_selected, $include ) );
}
}
wp_send_json( $ret );
}
非常感谢:)