Support » Plugin: WooCommerce Extra Product Sorting Options » Z-A putting smaller numbers between larger ones

Viewing 1 replies (of 1 total)
  • Plugin Author Beka Rice

    (@bekarice)

    Hi @phoez, it looks like you’re sorting from A-Z in this example, and it’s working as expected.

    All of your examples have the same letters, so they’re sorted this way / grouped together. Then they’re being sorted by the numbers they have. However, these numbers are not being compared as numbers.

    The reason your numeric portion is sorting by 19, 2, 20 is because it’s comparing them as “letters” instead of true numbers or integers. The WordPress codex explains why:

    Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use ‘meta_value_num’ instead for numeric values.

    Since we want to sort by product name, we sort by meta key (a “string” or letters). As such, we cannot use ‘meta_value_num’, or numerical sorting. You must choose which sorting is applied, both cannot be used simultaneous or one after the other.

    So in short, this will always be the result of alphabetical sorting. We are sorting by title here, so we need to sort by name, which means we cannot also sort by number after we sort by name.

    Unfortunately true “alphanumeric” or “natural” sorting like what you’re looking for is not possible with the orderby value using the built-in WP query / sorting. Sorry I don’t have better news for you here!

Viewing 1 replies (of 1 total)
  • The topic ‘Z-A putting smaller numbers between larger ones’ is closed to new replies.