Can I control the order of discussion questions?

I would like to manually control the order of discussion questions so that they follow the order of the course units. They naturally fall in the order created, but then the questions for the first units show up at the bottom of the list instead of at the top. Is there a way to control the discussion items so that certain items would always be at the top? For example, discussions for Unit 1 would be at the top, unit 2 next, etc.


  • Patrick
    • Support Monkey

    Hi there @Amber Lea Starfire

    I hope you had a great Christmas holiday!

    I just took a looksee on my test install to see if there is any way to get that done with built-in settings, but no joy there. Or perhaps CSS, but there are no specific classes or IDs assigned to the list elements, so that won't work either. Or perhaps a bit of php/jQuery wizardry, but I'm not a code ninja (yet).

    It may be possible with a custom query to join the IDs of the units with the unit questions and order them that way. But that can be tricky too as units can be re-ordered in the backend simply by dragging/dropping them on the course units screen in the admin.

    I'll see if one of our 2nd-level support wiz-kids can jump in here to land a hand though.

  • Amber Lea Starfire
    • Design Lord, Child of Thor

    Thanks, Patrick. I'm not even a code newbie, and I don't even know what a jQuery is <lol> so I guess that's probably not going to work for me. So maybe this will qualify as a feature request.

    What I would like is for discussions to function like forums, where the administrator can create certain topic areas and then students can create discussions or ask questions within those topics. Make sense?

    Lacking that, I thought that being able to order the discussion items would be helpful.

  • Hoang Ngo
    • Code Slayer

    Hi @Amber Lea Starfire,

    I hope you are well today and I'm sorry for the delay.

    Please add this code to your theme functions.php or use mu-plugins

    add_action('pre_get_posts', 'discussions_ordering');
    function discussions_ordering(WP_Query $query)
        if ($query->is_main_query()) {
        if ($query->get('post_type') == 'discussions') {
            $query->set('order', 'ASC');
            $query->set('meta_query', array(
                'key' => 'course_id',
                'meta_value' => $query->get('meta_value')
            $query->set('orderby', 'meta_value');
            $query->set('meta_key', 'unit_id');
            $query->set('meta_value', '');

    Let's see if it work for you :slight_smile:

    Best regards,
    Hoang Ngo

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.