{"id":6514950,"date":"2015-09-05T16:32:39","date_gmt":"2015-09-05T16:32:39","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/repeatable-fields-sortability\/"},"modified":"2016-08-30T17:39:59","modified_gmt":"2016-08-30T17:39:59","slug":"repeatable-fields-sortability","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/repeatable-fields-sortability\/","title":{"rendered":"Repeatable fields sortability"},"content":{"rendered":"<p>I&#8217;m wondering if the drag-ability of repeatable fields has some hidden sort value? I cannot figure out where the sort is stored; I did a print_r of the simple_fields_fieldgroup() and couldn&#8217;t find it.<\/p>\n<p>As a workaround I&#8217;ve had to put a sort field in, and manually update it. Surely there is a better way? <\/p>\n<p>Here is my code currently:<\/p>\n<pre><code>\/\/ now get simple fields. They may not be in the right order, so we build an array using the sort value\n\t\t$mysimple_fields_values = simple_fields_fieldgroup(&#039;sections&#039; );\n\t\t\/\/dprint_r($mysimple_fields_values);\n\t\t$simplevalues = array();\n\t\tforeach ($mysimple_fields_values as  $value) {\n\t\t\t$simplevalues[$value[&#039;sort&#039;]] = array(\n\t\t\t\t&#039;anchor&#039;=&gt;$value[&#039;anchor&#039;],\n\t\t\t\t&#039;subsection_class&#039;=&gt;$value[&#039;subsection_class&#039;],\n\t\t\t\t&#039;subsection_content&#039; =&gt; apply_filters(&#039;the_content&#039;, $value[&#039;subsection&#039;])\n\t\t\t\t);\n\t\t\t}\n\n\t\t$count_of_fields = count($mysimple_fields_values);\n\t\tfor ( $x = 0; $x &lt;=  ($count_of_fields); $x++) {\n\t\t\techo $simplevalues[$x][&#039;sort&#039;];\n\t\t\t$my_anchor = $simplevalues[$x][&#039;anchor&#039;];\n\t\t\tif ($my_anchor == &#039;&#039;) {continue;}\n\n\t\t\t$my_subsection_class = $simplevalues[$x][&#039;subsection_class&#039;];\n\t\t\t$my_subsection_content = $simplevalues[$x][&#039;subsection_content&#039;];\n\n\t\t\techo &quot;&lt;a name=&#039;$my_anchor&#039;&gt;&lt;\/a&gt;&quot;;\n\t\t\techo &quot;&lt;div id=&#039;$my_anchor&#039; class=&#039;subsection $my_anchor $my_subsection_class&#039;&gt;&quot;;\n\t\t\techo $my_subsection_content;\n\t\t\techo &quot;&lt;\/div&gt;&lt;!-- \/$my_anchor --&gt;\\n&quot;;\n\t\t\techo &#039;&lt;div class=&quot;clear&quot;&gt;&lt;\/div&gt;&#039;;\n\t\t\techo &quot;\\n\\n\\n&quot;;\n\n\t\t}<\/code><\/pre>\n<p>https:\/\/wordpress.org\/plugins\/simple-fields\/<\/p>\n","protected":false},"template":"","class_list":["post-6514950","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6514950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6514950\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6514950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}