Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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
Ajax 以编程方式设置Redux分拣机字段选项值_Ajax_Wordpress_Redux Framework - Fatal编程技术网

Ajax 以编程方式设置Redux分拣机字段选项值

Ajax 以编程方式设置Redux分拣机字段选项值,ajax,wordpress,redux-framework,Ajax,Wordpress,Redux Framework,我正在开发一个section sorter插件,为此我使用Redux设置了一个简单的选项页面,其中只有sorter字段。问题是,我不能把启用的值编程,我已经尝试了几种方法,但似乎没有任何工作 我正在使用AJAX获取主页中所有节标记的ID,然后,我将节的ID发送到选项文件(Redux options文件,sample-config.php,或者在我的示例中是sorting-sections-options.php)中的函数,如下所示: 这是我的JS/JQ/AJAX代码: jQuery(docume

我正在开发一个section sorter插件,为此我使用Redux设置了一个简单的选项页面,其中只有sorter字段。问题是,我不能把启用的值编程,我已经尝试了几种方法,但似乎没有任何工作

我正在使用AJAX获取主页中所有节标记的ID,然后,我将节的ID发送到选项文件(Redux options文件,sample-config.php,或者在我的示例中是sorting-sections-options.php)中的函数,如下所示:

这是我的JS/JQ/AJAX代码:

jQuery(document).ready(function($){
var sections_ids = {action: 'save_sections_ids'};
$.get(window.location.protocol + "//" + window.location.host + "/futbol-americano", function(data) {
var sections_elements = $(data).find("section");
sections_elements.each(function(){
var section_id = $(this).attr("id");

sections_ids[section_id] = section_id; 
console.log(section_id);

}); 
pass_ids_to_server(sections_ids);

});

function pass_ids_to_server(sections_ids){
    $.ajax({
        url : sorting_sections.ajax_url,
        type : 'post',
        data : sections_ids,
        success : function( response ) {             
            alert(response);
        }
    }); 
} 
});
这是从ajax接收数据的函数:

这是当前的表单,但我尝试了循环$\u POST变量并返回一个数组以放置在“enabled”=>$数组中,以及其他几种方法,因此我认为asinchronous调用可能是在函数之前加载字段,并决定将数据存储在user meta中

add_action( 'wp_ajax_save_sections_ids', 'save_sections_ids_sorting_sections' );

function save_sections_ids_sorting_sections() {

$user_id = get_current_user_id();
update_user_meta($user_id, "set-sections", $_POST);

}
AJAX调用起作用,接收数据的函数也起作用。数据存储在数据库的user_meta表中。但当我这样做时:

$user_id = get_current_user_id();
$get_sections_array = get_user_meta($user_id, "set-sections", true);
//Returns false but if var_dumped inside the save_sections_ids_sorting_sections() function, it shows the array correctly in an alert box (from succes on ajax call).

$sorter_field = array(
'section_id' => 'basic',
'id' => 'opt-homepage-layout-3',
'type' => 'sorter',
'title' => 'Este es el titulo',
'desc' => 'this is the description',
'compiler' => 'true',
'options' => array(
'disabled' => array(
),
'enabled' => $get_sections_array;
));

Redux::setField($opt_name, $sorter_field );
//The Redux::setField($opt_name, $sorter_field ); works if I define $sorter_field manually before the instance.
我在“选项”页面中收到以下错误消息:

警告:array_merge():参数#2不是第81行C:\xampp\htdocs\futbol americano\wp content\plugins\sorting sections\ReduxFramework\ReduxCore\inc\fields\sorter\field\u sorter.php中的数组

警告:为C:\xampp\htdocs\futbol americano\wp content\plugins\sorting sections\ReduxFramework\ReduxCore\inc\fields\sorter\field\u sorter.php中的foreach()提供的参数无效,第103行

我希望有人能帮上忙

提前谢谢