I have support ticket system which i have built using wordpress.

The basic functionality is that when a "ticket" is created, it creates a post. When an admin replies, it then add a child post to the original post.

My question is how can i order my posts by the child post_date is ASC order?

My query args at the moment are:

$args = array(
  'post_type' => 'support_tickets',
  'numberposts' => -1,
  'post_parent' => 0,
  'orderby' => 'date',
  'order' => 'DESC'  );

This only obviously orders the parent post's in ASC by date. Is what i require achievable?

  • 1
    I imagine that you could get this to work with enough effort, but I am not sure you could get it to work efficiently. You are talking about a lot of tricky SQL and/or PHP manipulation of the data. I would suggest that your design is going to cause you a lot of pain. Use comments, or a custom built table/interface.
    – s_ha_dum
    Commented Nov 27, 2013 at 15:50
  • @s_ha_dum yes i did imagine it would be a lot of work and headache... i will spend some more time looking into it, and if no joy i will go down the route of using comments or another custom solution
    – danyo
    Commented Nov 27, 2013 at 16:00
  • What solution did you land on?
    – Jen
    Commented Nov 17, 2016 at 15:21

1 Answer 1


You should be able to do this with the get_children function (see the codex),

$ticket_id = 34; // assume you want to retried the replies of ticket post id=34
$args = array(
  'post_type' => 'support_tickets',
  'numberposts' => -1,
  'post_parent' => $ticket_id,
  'orderby' => 'date',
  'order' => 'DESC'  );
$replies = get_children( $args );

Assuming that your custom post support_tickets has been registered with the attribute hierarchical set to true (see codex).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.