Title: GRoups priority
Last modified: November 11, 2020

---

# GRoups priority

 *  Resolved [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/)
 * Hi!
 * is there any way to order the groups by priorities just like the priorities of
   the rules within the groups?
    Are the groups loaded in alphabetical order?
 * regards

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13650867)
 * Hi!
 * There is a position column in the wp_redirection_groups table, but it is not 
   queried at request time for all matching URLs.
 * with just adding a joing and order by that position wil order all the rules following
   the groups order.
    I mean: file: plugins/redirection/models/redirect/redirect.
   php function: get_for_matched_url
 * change:
 * `SELECT * FROM {$wpdb->prefix}redirection_items WHERE match_url=%s OR match_url
   ='regex'`
 * to
 *     ```
       SELECT {$wpdb->prefix}redirection_items.*, {$wpdb->prefix}redirection_groups.position FROM {$wpdb->prefix}redirection_items 
       JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_items.group_id = {$wpdb->prefix}redirection_groups.id
       WHERE match_url=%s OR match_url='regex'
       ORDER BY {$wpdb->prefix}redirection_groups.position asc
       ```
   
    -  This reply was modified 5 years, 6 months ago by [gonza.ar](https://wordpress.org/support/users/gonzaar/).
 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13650882)
 *     ```
       	public static function get_for_matched_url( $url ) {
       		global $wpdb;
   
       		$url = new Red_Url_Match( $url );
       		$sql = "SELECT {$wpdb->prefix}redirection_items.*, {$wpdb->prefix}redirection_groups.position
                       FROM {$wpdb->prefix}redirection_items
                       JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_items.group_id = {$wpdb->prefix}redirection_groups.id
                       WHERE match_url=%s OR match_url='regex'
                       ORDER BY {$wpdb->prefix}redirection_groups.position asc";
   
       		$rows = $wpdb->get_results( $wpdb->prepare( $sql, $url->get_url() ) );
   
       		$items = array();
       		if ( count( $rows ) > 0 ) {
       			foreach ( $rows as $row ) {
       				$items[] = new Red_Item( $row );
       			}
       		}
   
       		usort( $items, array( 'Red_Item', 'sort_urls' ) );
   
       		return $items;
       	}
       ```
   
 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13651043)
 * There is no group priority. They are loaded in the order on the groups page, 
   or alphabetical.
 * The priority column in the groups table is deprecated and will be removed.
 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13651097)
 * Hi John,
 * The problem is that it is difficult to follow the position of the rules when 
   we have a lot. For example. we have 45 groups and 40 rules in each one. If we
   need to add a rule that needs to be validated before another rule, it will be
   difficult to find the position of the rules with similar matches, and it will
   also be difficult to reposition them.
 * is there any way that the plugin solves it in another way?
    REgards
 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13651353)
 * I don’t know what kind of rules you are trying to create, but it does sounds 
   like it is very complex, and will be complex regardless of group positioning.
   I would look into trying to simplify the rules. Generally the position is used
   for the exceptions, not for the majority, and it suggests to me that there is
   maybe a better way.
 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13654460)
 * Hi John,
 * Thanks for the reply, yes, we have complex rules and these rules follow priorities.
   
   Is there a hook that allows me to alter the response ?
 * Regards
 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13654631)
 * Alter what response?
 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13655224)
 * John,
 * The responose of the function “get_for_matched_url”
    I would like to know if 
   there is a hook after the function that does that query to organize the response
   of possible all redirects that match the URL.
 * Regards
 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13655259)
 * There are WordPress filters you can use to modify database queries, but nothing
   in Redirection.
 * I would strongly suggest looking into a simpler solution. Maybe if you can give
   an example of your situation then there may be an easier alternative.
 *  Thread Starter [gonza.ar](https://wordpress.org/support/users/gonzaar/)
 * (@gonzaar)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13655329)
 * Hi,
 * Here is an example:
    We have 40 groups with 30 rules each. In the last group (
   Z) we have the following rule in the position 20 :
 * “^(?i)test(.*)/?$” “/” [R=301,L]
 * we have in the second group (B) the following rule in the position 30:
 * “^testguest/?$” “[https://test.com/test&#8221](https://test.com/test&#8221); [
   R=301,L]
 * For the plugin, the rule of the group Z will be first because was created first,
   but we don’t want that. Of course I can just change the position of the rule 
   in the second group to 19, and then the plugin will take the rule of the group
   B first.
    The problem is that we have 1200 rules, and every day we add and remove
   rules, will be hard to follow the position of the rules.
 * For this reason I think that having orders in the groups, in addition to the 
   orders of the rules within the groups, would be a great functionality.
 * Regards
    -  This reply was modified 5 years, 6 months ago by [gonza.ar](https://wordpress.org/support/users/gonzaar/).
    -  This reply was modified 5 years, 6 months ago by [gonza.ar](https://wordpress.org/support/users/gonzaar/).
    -  This reply was modified 5 years, 6 months ago by [gonza.ar](https://wordpress.org/support/users/gonzaar/).
 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13663974)
 * Priority does not need to be unique across every redirect. It only needs to enable
   whatever small set of stacked redirects to work. For example, your Z rule could
   be priority 100000, and it will always be last.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘GRoups priority’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [John Godley](https://wordpress.org/support/users/johnny5/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/groups-priority/#post-13663974)
 * Status: resolved