Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other WordPress: Use query_posts to order_by tag alphabetically

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31154
    Johnnyb
    Member

    I’ve been googling around for a while and going through the WP codex to try to find a way to do this. I can use ‘order_by=tag’ within query_posts but it doesn’t order the posts alphabetically by tag name. I’ve tried combinations using ‘order=ASC’ and ‘order=DESC’ but nothing seems to work. Does anyone know if there’s even support for this in WordPress using query_posts? Would I have to try a different approach and maybe use an array?

    Many thanks in advance, I really appreciate it.

    #67613
    clokey2k
    Participant

    Just checked the codex, and it doesn’t look like the tag ordering is possible outright. Probably because each post could potentially have hundreds of tags. Which tag would it choose to organise with?

    http://codex.wordpress.org/Function_Reference/query_posts#Orderby_Parameters

    Is this related to your previous discussion about tabs and sorting? What is the end result of ordering by tags?

    #67351
    Johnnyb
    Member

    Hey clokey thanks for the reply again, really appreciate your input. The filtering blocks worked great and I was able to categorize the posts into tabs by their tag-name. While the filtering blocks allow me to filter certain posts it doesn’t allow me to display all of the posts in a specific order (in this case alphabetically). I have 5 options, the first is ‘All’ the second is ‘Type’ and the last 3 are categories. The ‘All’ and the categories work fine using the filtering blocks, but the ‘Type’ option needs to list all of the posts in order by tag-name alphabetically.

    I understand what you’re saying about there being multiple tags and not knowing which one to use to order by, I was hoping it would just take the first one and use that, but unfortunately not. I thought that order_by=tag was ordering the posts by tag ID, but after further investigation it was just coincidence!

    I’m by no means an expert in PHP but do you know whether it’s actually possible to achieve this?

    #67355
    clokey2k
    Participant

    I think you’ll have to move back to the drawing board on this one…

    Ordering by tag’s could be done using:

     

    Which would create an array of all tags used. Then loop through each tag and run a loop of posts containing that tag. It would be messy… and any post with multiple tags will appear in the list for each tag it contains.

    You might have to resort to an AJAX call to load them…

    #67361
    Johnnyb
    Member

    Yeh I’m gonna have to go back and rethink this one, might be more trouble than it’s worth for me to organize posts this way. Thanks again for the help, really appreciate it.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Other’ is closed to new topics and replies.