• I’ve just inserted the Latest Posts widget in my sidebar, which allows me to rank the list alphabtically. However, I would like it to ignore instances of ‘The’, ‘A’ and ‘An’. Any tips on how this is possible, please?

    TIA

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Altering the widget is not very desirable, you’d essentially need to create your own version. It is possible to alter the SQL query used via action or filter hooks. It would be possible to order query results based on the result of REGEXP_REPLACE() or similar SQL functions. I’m unsure of the correct syntax, but in theory this is possible. I suspect it would not be very performative though.

    The above approach is complicated by the need to discern the widget’s query from all others. There are likely a distinguishing set of query vars you could check for before altering the query.

    A simpler solution would be to always ensure the post’s slugs never include articles like ‘A’, ‘The’, etc. Then you can simply sort posts based on name (post slug) instead of the title. You could use the ‘wp_unique_post_slug’ filter to automatically remove articles from post slugs. This would not help with all existing post slugs that begin with an article. A series of search and replace operations could fix up those existing posts.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.