I have two custom post types (Branding Elements and Products) that I’m showing on a single page, and the client wants to be able to control the sort order of the page.
What would be the best course of action for creating a way for the client to re-order two post types with a drag n drop interface? Because they’re 2 different post types, none of the currently available plugins are suitable.
It’s common to utilize the WordPress navigational menu UI to get the drag/drop feature for free.
I think there are already some answers, on this site, explaining this better than I can, but I can’t seem to find them for you. So let my try to construct one simple example:
We go to Appearance/Menus and create a menu with e.g. the
mylist
menu id.Then we drag/drop posts onto that menu and save it.
Add the following shortcode to a page/post content:
with the following code snippet to support it:
PS: When writing this example I did at least two mistakes at first 😉
I first forgot to fetch the posts in the
posts__in
order, to match the nav menu order.Secondly I used the
db_id
as the post ID’s instead, of theobject_id
field.After fixing that, this seemed to run as expected, so I just post it here now 😉
This isn’t going to work with your current setup. You need to create a single post type and split the posts via a custom taxonomy which would have two terms: ‘Branding Elements’ and ‘Products’. This is the only way to realistically combine two post types into one manageable list that can be reordered by drag-and-drop.
From there you can display the order via
'order' => 'ASC', 'orderby' => 'menu_order'
in your query$args
and use Simple Page Ordering to drag-and-drop them in the dashboard.Also, when registering your post type you’ll need to include
'hierarchical' => 'page-attributes'
. So that the posts can be reordered.Use categories.
Make a category that you can apply to both post types, and then use this plugin:
https://wordpress.org/plugins/custom-post-order-category/
To order all posts in that category.
Don’t show the category on the front end of your website, as its purpose is purely to help relate the two post types for this plugin to use.