Skip to main content

Why drag-and-drop ordering lives in the Post Types extension and works on every post type, not only the ones it creates

· 3 min read
Jon-Michael Lastimosa
Senior Web Developer

The question: "Is it possible to add drag and dropping to arrange the custom post type? Should we add this feature in the custom post type extension?" — asked when a client wanted one casino at number 1 and another at number 2 on a review toplist, and the only lever was the reviews' publish dates.

Context​

The review toplists on the casino sites were sorted by publish date (one theme asked for a "menu order" direction that WordPress ignores, so it fell back to newest first). Putting a site at number 1 meant faking its date, which breaks again the next time a review is published. These requests are routine on affiliate sites, and the same need shows up for team members, testimonials and services.

The review post types on those sites are registered by the child theme in code (the Base Casino model), not by the Post Types extension, so the extension's own screen did not even list them.

Options considered​

  • Keep using dates. No code, but it misuses the date, breaks on the next publish, and cannot be explained to an editor.
  • Per-theme code. Each casino theme adds its own ordering screen. Duplicated on every site and drifts.
  • A third-party ordering plugin. Works, but adds a plugin to sites we are actively slimming down, and its sorting rules would not know our elements.
  • Ordering in the Post Types extension, for the extension's own types only. Clean, but misses exactly the theme-registered review types that prompted the question.
  • Ordering in the Post Types extension, for every post type with an admin screen. One switch per type, theme- and plugin-registered types included.

Decision​

Drag-and-drop ordering is part of the Post Types extension (an Ordering tab), switched on per post type, for any type with an admin screen. The order is WordPress's own menu_order; rows are dragged on the type's normal list screen and save as they drop. Queries for one ordered type that ask for no order follow it; queries that name an order (date, rating, a picked set) keep theirs. The switches travel in the extension's JSON export.

Why​

  • menu_order is already there on every post, is what Pages use, and is understood by WP_Query, themes and our Reviews Table ("Manual (page order)"). No new table or meta, and switching it off loses nothing.
  • Covering every type is the point: the lists that need ordering most are registered by themes, and asking people to redefine them in the extension first would be a migration, not a feature.
  • Only unordered queries follow it, so turning it on can never silently reshuffle a page that asked for dates or ratings.
  • First switch-on numbers items in date order, so the site looks the same until someone drags.
  • It belongs with post types — the screen where people already manage content types — rather than in a separate extension for one checkbox and a list-screen handle.