Skip to content
Advertisement

Alphabetical filtering of custom post type in WordPress results

I’m working on a custom post type archive and I want to add an A-Z filtering menu. I managed to pretty much get it working following this thread (Create alphabetical Pagination in wordpress) but I dont understand how my initial page (/exposants) can show all the results.

JavaScript

I imagine I’d have to replace the else {$letter = $firstLetters[0];} but I have no idea with what.

Thanks in advance for your precious support.

EDIT!

Here is the solution that ended up working flawlessly!

So in functions.php

JavaScript

And here is the page

JavaScript

Advertisement

Answer

If I understand the problem correctly, here’s an slightly optimized version of your code. I’ve taken the liberty of decoupling your php and your html as much as I could for clarity.

It’s not tested, it may take a few tweaks, but overall I hope this does the trick!

In your functions.php file, add this, which will allow you to filter your database queries by first letter:

JavaScript

Then:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement