{"action":"created","issue":{"url":"https://api.github.com/repos/reduxframework/redux-framework/issues/2668","labels_url":"https://api.github.com/repos/reduxframework/redux-framework/issues/2668/labels{/name}","comments_url":"https://api.github.com/repos/reduxframework/redux-framework/issues/2668/comments","events_url":"https://api.github.com/repos/reduxframework/redux-framework/issues/2668/events","html_url":"https://github.com/reduxframework/redux-framework/issues/2668","id":112045078,"number":2668,"title":"Set Redux sorter field values programatically","user":{"login":"laloptk","id":10329799,"avatar_url":"https://avatars.githubusercontent.com/u/10329799?v=3","gravatar_id":"","url":"https://api.github.com/users/laloptk","html_url":"https://github.com/laloptk","followers_url":"https://api.github.com/users/laloptk/followers","following_url":"https://api.github.com/users/laloptk/following{/other_user}","gists_url":"https://api.github.com/users/laloptk/gists{/gist_id}","starred_url":"https://api.github.com/users/laloptk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laloptk/subscriptions","organizations_url":"https://api.github.com/users/laloptk/orgs","repos_url":"https://api.github.com/users/laloptk/repos","events_url":"https://api.github.com/users/laloptk/events{/privacy}","received_events_url":"https://api.github.com/users/laloptk/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-18T22:09:16Z","updated_at":"2015-10-19T04:54:51Z","closed_at":"2015-10-18T23:15:22Z","body":"I'm working on a section sorter plugin, for that I used Redux to set a simple options page with only the sorter field. The thing is, I can't put the enabled values programatically, I have tried several ways and nothing seems to work.\r\n\r\nI am using AJAX to get the ids of all section tags in homepage, then, I send the sections' ids to a function in the options file (Redux options file, sample-config.php, or in my case sorting-sections-options.php , like this:\r\n\r\nThis is my JS/JQ/AJAX code:\r\n\r\njQuery(document).ready(function($){\r\nvar sections_ids = {action: 'save_sections_ids'};\r\n$.get(window.location.protocol + \"//\" + window.location.host + \"/futbol-americano\", function(data) {\r\nvar sections_elements = $(data).find(\"section\");\r\nsections_elements.each(function(){\r\nvar section_id = $(this).attr(\"id\");\r\n\r\nsections_ids[section_id] = section_id; \r\nconsole.log(section_id);\r\n\r\n}); \r\npass_ids_to_server(sections_ids);\r\n\r\n});\r\n\r\nfunction pass_ids_to_server(sections_ids){\r\n    $.ajax({\r\n        url : sorting_sections.ajax_url,\r\n        type : 'post',\r\n        data : sections_ids,\r\n        success : function( response ) {             \r\n            alert(response);\r\n        }\r\n    }); \r\n} \r\n});\r\n\r\nThis is the function that receives the data from ajax:\r\n\r\nThis is the form is has currently, but I have tried looping the $_POST variable and returning an array to place inside the 'enabled' => $array and several other ways, so I though the asinchronous call could be doing that the field load before the function and decided to store the data in user meta.\r\n\r\nadd_action( 'wp_ajax_save_sections_ids', 'save_sections_ids_sorting_sections' );\r\n\r\nfunction save_sections_ids_sorting_sections() {\r\n\r\n$user_id = get_current_user_id();\r\nupdate_user_meta($user_id, \"set-sections\", $_POST);\r\n\r\n}\r\n\r\nThe AJAX call works, and the function that receives the data works as well. The data stores in the user_meta table in database. But when I do this:\r\n\r\n$user_id = get_current_user_id();\r\n$get_sections_array = get_user_meta($user_id, \"set-sections\", true);\r\n//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).\r\n\r\n$sorter_field = array(\r\n'section_id' => 'basic',\r\n'id' => 'opt-homepage-layout-3',\r\n'type' => 'sorter',\r\n'title' => 'Este es el titulo',\r\n'desc' => 'this is the description',\r\n'compiler' => 'true',\r\n'options' => array(\r\n'disabled' => array(\r\n),\r\n'enabled' => $get_sections_array;\r\n));\r\n\r\nRedux::setField($opt_name, $sorter_field );\r\n//The Redux::setField($opt_name, $sorter_field ); works if I define $sorter_field manually before the instance.\r\n\r\nI get the following error message in the options page:\r\n\r\nWarning: array_merge(): Argument #2 is not an array in C:\\xampp\\htdocs\\futbol-americano\\wp-content\\plugins\\sorting-sections\\ReduxFramework\\ReduxCore\\inc\\fields\\sorter\\field_sorter.php on line 81\r\n\r\nWarning: Invalid argument supplied for foreach() in C:\\xampp\\htdocs\\futbol-americano\\wp-content\\plugins\\sorting-sections\\ReduxFramework\\ReduxCore\\inc\\fields\\sorter\\field_sorter.php on line 103\r\n\r\nI hope someone can help with this.\r\n\r\nThanks in advance."},"comment":{"url":"https://api.github.com/repos/reduxframework/redux-framework/issues/comments/149098482","html_url":"https://github.com/reduxframework/redux-framework/issues/2668#issuecomment-149098482","issue_url":"https://api.github.com/repos/reduxframework/redux-framework/issues/2668","id":149098482,"user":{"login":"laloptk","id":10329799,"avatar_url":"https://avatars.githubusercontent.com/u/10329799?v=3","gravatar_id":"","url":"https://api.github.com/users/laloptk","html_url":"https://github.com/laloptk","followers_url":"https://api.github.com/users/laloptk/followers","following_url":"https://api.github.com/users/laloptk/following{/other_user}","gists_url":"https://api.github.com/users/laloptk/gists{/gist_id}","starred_url":"https://api.github.com/users/laloptk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laloptk/subscriptions","organizations_url":"https://api.github.com/users/laloptk/orgs","repos_url":"https://api.github.com/users/laloptk/repos","events_url":"https://api.github.com/users/laloptk/events{/privacy}","received_events_url":"https://api.github.com/users/laloptk/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T04:54:51Z","updated_at":"2015-10-19T04:54:51Z","body":"Ok, I understand, Thanks anyway, You are doing a great work with Redux. "}}