wordpress query – orderby child post date

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.

Read More

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?

Related posts

1 comment

  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).

Comments are closed.