• down vote favorite

    I working with a parent category, and we call these category “colors”, this category have two child categories we named here childcategory “red” and another childcategory “blue”.

    When i go to the category page i see both child categories but mixed up, this is the result of the date where posts in the childcategories are made.

    My problem is i have to make the category “colors” where the posts are sorted in two blocks, first all the posts of childcategory red (with content) and thereafter the posts of childcategory blue (with content) also each block should be sorted to the date they made. if a post is made in childcategory red today and at the same day a post is made in childcategory blue they chould be present in their own blocks not the one after the other…

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You want to set the query to orderby taxonomy terms. Unfortunately, WP_Query does not offer a way to do this. You need to add the orderby clause to the query yourself. This is done by hooking the ‘posts_orderby’ filter and returning the correct clause.

    What’s the correct clause? I don’t know, sorry. You may be able to figure it out by hooking ‘posts_requests’ where you can examine the entire query string. From this you can determine how to properly reference the taxonomy terms column.

    The other issue is these filters apply to all queries. Your script needs to determine if the query is a colors category archive query before adding in the orderby clause. Your filter callback is actually passed two items, the default clause and the query object itself. Examining the query vars from the query object should let you determine the correct queries.

Viewing 1 replies (of 1 total)
  • The topic ‘WP Category page sorting the child categories in group’ is closed to new replies.