From 25e077fbfaff7391a6d1fa088e1f84504dfac679 Mon Sep 17 00:00:00 2001 From: Gleb Kemarsky Date: Mon, 10 Feb 2020 23:04:19 +0100 Subject: [PATCH 1/2] Fix #66. Allow terms to match the order in the `include` parameter --- simple-custom-post-order.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/simple-custom-post-order.php b/simple-custom-post-order.php index 22fd989..d05de50 100644 --- a/simple-custom-post-order.php +++ b/simple-custom-post-order.php @@ -64,9 +64,9 @@ function __construct() { add_filter('get_next_post_sort', array($this, 'scporder_next_post_sort')); add_filter('get_terms_orderby', array($this, 'scporder_get_terms_orderby'), 10, 3); - add_filter('wp_get_object_terms', array($this, 'scporder_get_object_terms'), 10, 3); - add_filter('get_terms', array($this, 'scporder_get_object_terms'), 10, 3); - + add_filter('wp_get_object_terms', array($this, 'scporder_get_object_terms'), 10, 4); + add_filter('get_terms', array($this, 'scporder_get_terms'), 10, 3); + add_action( 'admin_notices', array( $this, 'scporder_notice_not_checked' ) ); add_action( 'wp_ajax_scporder_dismiss_notices', array( $this, 'dismiss_notices' ) ); @@ -237,7 +237,6 @@ public function refresh() { $tags = $this->get_scporder_options_tags(); if (!empty($objects)) { - foreach ($objects as $object) { $result = $wpdb->get_results(" SELECT count(*) as cnt, max(menu_order) as max, min(menu_order) as min @@ -535,6 +534,9 @@ public function scporder_get_terms_orderby($orderby, $args) { if (is_admin()) return $orderby; + if (isset($args['include']) && isset($args['orderby']) && 'include' === $args['orderby']) + return $orderby; + $tags = $this->get_scporder_options_tags(); if (!isset($args['taxonomy'])) @@ -558,12 +560,19 @@ public function scporder_get_terms_orderby($orderby, $args) { return $orderby; } - public function scporder_get_object_terms($terms) { + public function scporder_get_object_terms($terms, $object_ids, $taxonomies, $args) { + $this->scporder_get_terms($terms, $taxonomies, $args); + } + + public function scporder_get_terms($terms, $taxonomies, $args) { $tags = $this->get_scporder_options_tags(); if (is_admin() && isset($_GET['orderby'])) return $terms; + if (isset($args['include']) && isset($args['orderby']) && 'include' === $args['orderby']) + return $terms; + foreach ($terms as $key => $term) { if (is_object($term) && isset($term->taxonomy)) { $taxonomy = $term->taxonomy; From 091819d9414355e9f42db95e3684720a289ee227 Mon Sep 17 00:00:00 2001 From: Gleb Kemarsky Date: Tue, 11 Feb 2020 08:58:47 +0100 Subject: [PATCH 2/2] Added a missing `return` to the method --- simple-custom-post-order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simple-custom-post-order.php b/simple-custom-post-order.php index d05de50..20b0862 100644 --- a/simple-custom-post-order.php +++ b/simple-custom-post-order.php @@ -561,7 +561,7 @@ public function scporder_get_terms_orderby($orderby, $args) { } public function scporder_get_object_terms($terms, $object_ids, $taxonomies, $args) { - $this->scporder_get_terms($terms, $taxonomies, $args); + return $this->scporder_get_terms($terms, $taxonomies, $args); } public function scporder_get_terms($terms, $taxonomies, $args) { @@ -685,4 +685,4 @@ function scporder_uninstall_db() { $result = $wpdb->query($query); } delete_option('scporder_install'); -} \ No newline at end of file +}