Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#4335 closed defect (bug) (fixed)

Intrinsic Category Sorting (by ID) Changed in 2.2

Reported by: iacas's profile iacas Owned by:
Milestone: 2.2.1 Priority: normal
Severity: normal Version: 2.2
Component: General Keywords:
Focuses: Cc:

Description

Category sorting used to take place by ID, and without a proper "primary category," I'm now finding with WordPress 2.2 that the permalinks as well as the order of the categories is flipped from previous behavior.

I've written about this more here: http://tinyurl.com/yp3vfn

I'd like to call this a bug as the behavior, so far as I can tell, was unplanned and unannounced, and I'd like the behavior reverted.

Attachments (1)

cat_id_order__branches_2.2.diff (1.1 KB) - added by markjaquith 17 years ago.
Pick category-based post permalink by lowest category ID (patch for 2.2 branch)

Download all attachments as: .zip

Change History (9)

#1 @Otto42
17 years ago

What categories? What sort? What function are you calling to do what? Categories changed a lot between 2.0 and 2.1, so it's difficult to understand what it is that you're doing here. Even reading your blog post left me unenlightened.

What is the PHP code that you are running, or what are you doing exactly?
What does it do, for each version of Wordpress?
What did you expect it to do instead?

That's what we need to know.

#2 @iacas
17 years ago

Otto, so far as I can tell this change is from 2.1.x to 2.2. I have PHP 4.3.9 installed.

Permalinks used to be built from the category with the lowest ID. Now they're built from the category with the highest ID. Category lists used to be in "low to high" order, and now that order too appears reversed.

I'm using only standard WP functions. I don't manually build my own URLs.

Some specific examples:
http://thesandtrap.com/tags/reviews/eagle_sticks_golf_club_zanesville_oh_review
versus
http://thesandtrap.com/courses/eagle_sticks_golf_club_zanesville_oh_review

or

http://thesandtrap.com/tags/hot_topics/the_cost_of_being_a_fan
versus
http://thesandtrap.com/the_numbers_game/the_cost_of_being_a_fan

#3 @iacas
17 years ago

I believe I've worked around this - for now - by setting the categories with cat_ID of 98, 99, 100, and 101 to their negatives: -98, -99, -100, and -101. Corresponding updates to wp_post2cat were also made (UPDATE wp_post2cat set category_id = '-99' WHERE category_id = '99')

I still believe this type of behavior is a bug - the behavior changed, unannounced and I believe unintended - and it certainly highlights the need for a "primary" category feature since categories are (often) intrinsic to URL-building in WordPress.

#4 @ryan
17 years ago

			$cats = get_the_category($post->ID);
			$category = $cats[0]->category_nicename;

We need to sort cats by ID before taking setting $category to the first cat in the list.

#5 @ryan
17 years ago

That's in get_permalink().

#6 @markjaquith
17 years ago

There's a patch for 2.2. Try that on for size.

I'm leaving this out of the codebase until [4349] gets fixed in trunk, so I can commit fixes to both branches at the same time without risk of regression.

@markjaquith
17 years ago

Pick category-based post permalink by lowest category ID (patch for 2.2 branch)

#7 @markjaquith
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5590]) switch to term_id and name for category sorting. see #4189. sort by term_id for category permalinks, by name for get_the_category(). fixes #4335 for trunk. Props Erik Barzeski for the find.

#8 @markjaquith
17 years ago

(In [5591]) sort by cat_ID for category permalinks, by name for get_the_category(). fixes #4335 for 2.2. Props Erik Barzeski for the find.

Note: See TracTickets for help on using tickets.