WooCommerce - excelling eCommerce
Remove the word "The" in sort/order alphabetically (3 posts)

  1. mjb709
    Posted 2 years ago #

    Hi everyone,
    I'm looking to remove the word "The" in my product sort/order when arranging alphabetically. I think a hook or filter that would remove the word "The" when it's the first word would work.

    For example, I have a product called "The Smiths" and I want it to be in the S section and not the T section since people would look in the S section.

    Has anyone done this or know of anyone who has done this customization? It seems like it would be a pretty helpful addition to WooCommerce as a standard feature.



  2. bheadrick
    Posted 2 years ago #

    this should do it:

    add_filter('posts_orderby', 'edit_posts_orderby');
    function edit_posts_orderby($orderby_statement) {
    	$orderby_statement =
    str_replace('title','replace(title,"the ","")');
    	return $orderby_statement;
  3. KaitlinFNF
    Posted 2 years ago #

    This code seemed to work beautifully, but then I noticed as I was adding products that some of them were just going to the bottom of the list and were no longer sorting alphabetically. I was troubleshooting and took the code away and they all magically resorted themselves alphabetically, but when I put the code back in they go wonky again.

    Any idea why that would be? Is there a fix?


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic