View Sidebar
Sorting WPAlchemy Metabox Grouped Fields

Sorting WPAlchemy Metabox Grouped Fields

September 6, 2012 8:11 pm0 comments

I needed to change the sort order of my grouped fields. On a theme I was developing, there was a custom post type for Albums. Each album needed multiple attached song samples to load in a jPlayer playlist. I used WPAlchemy to include metaboxes for the administrator to upload his own song samples. But he wanted to be able to re-order/sort the songs after he uploaded them.

This was the solution I found on the class author’s website. It enables an easy, “drag to sort” function for sorting the meta box fields.

http://www.farinspace.com/sorting-wordpress-meta-box-fields/

The above page has two videos showing how to code the sort solution. For your use, I’ve included the text of the code below:

<p id="sort_warning" style="display:none; color:red;">
	Remember to click Save Changes or Update to save your sort order!
</p>

<style>
	#wpa_loop-links .wpa_group
	{ border: 1px solid #ccc;
	padding:10px; margin: 0 10px 15px; background-color:#fff; }
</style>

<script type="text/javascript">
	//<![CDATA[
	jQuery(function($)
	{
		$('#wpa_loop-links').sortable(
		{
			change: function()
			{
				$('#sort_warning').show();
			}
		});
	});
	//]]>
</script>

Many thanks to Dimas for providing this class and this sort solution.

Peace and long life

Leave a reply