WP Manifestindependent plugin directory
manifest / developer / mjj-sort-numbers

MJJ Sort Numbers

A table and API to sort objects based on their numerical values.

by JJ Jay · github.com/tharsheblows/mjj-sort-numbers · website

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/tharsheblows/mjj-sort-numbers/archive/refs/heads/master.zip

Readme

MJJ Sort Numbers

This uses a table which is used for sorting posts and comments based on their numerical metavalues. It's currently only working for posts and the metavalues to sort must be numbers. You will need to make the table yourself:

--
-- Table structure for table `wp_mjj_sort_posts`
--

CREATE TABLE IF NOT EXISTS `wp_mjj_sort_posts` (
  `ID` int(20) unsigned NOT NULL AUTO_INCREMENT,
  `object_id` int(20) unsigned NOT NULL,
  `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `meta_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `sort_value` decimal(7,4) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `object_id` (`object_id`,`meta_key`),
  KEY `sort` (`meta_key`,`sort_value`,`post_date`)
) ;

How it works:

  • in admin, go to Tools->MJJ Sort Numbers Tools
  • add in the meta key you'd like to sort into the correct post type and a query var so you can access it.
  • if you already have entries for this in the postmeta table, use "Repopulate sort table" to move them to wp_mjj_sort_posts
  • to get the sorted lists, use ?{$metakey}=asc to sort them in ascending order and ?{$metakey}=desc to sort them in descending order

It only returns posts which are in the sort table, so you need to make sure each post has an entry for it if you'd like it to be included. For example, I'm using this with a ratings plugin and giving unrated posts an initial value of -1.

This is tailored to what I need. Please don't use this as a finished plugin, it's more a starting point at the moment.

Read the full README on GitHub →