• I am working with the events manager plugin on a site. I have managed to add an extra column to the posts admin page which displays the event start date.

    What i’d like to be able to do is order the posts by the event start date, in the same way you can order by date and title. Is this possible?

    Cheers

    Heres the code ive added to my functions file:

    function my_columns($columns) {
        $columns['event'] = 'Event Date';
        return $columns;
    }
    
    function my_show_columns($name) {
        global $post;
        switch ($name) {
            case 'event':
                $event = get_post_meta($post->ID, '_EventStartDate', true);
                echo $event;
        }
    }
    
    add_filter('manage_posts_columns', 'my_columns'); // post columns
    add_action('manage_posts_custom_column',  'my_show_columns'); // Add custom column

Viewing 1 replies (of 1 total)
  • dpc036, I had the same question a few days ago.

    It was not easy for me to find out how to make my custom columns sortable. This article helped me a lot: https://scribu.net/wordpress/custom-sortable-columns.html

    You’ll need 3 hooks to do the job:

    1. manage_edit-{post-type}_columns
    2. manage_edit-{post-type}_sortable_columns
    3. manage_posts_custom_column

    While the first hook tells WP: “Ok, put this column here for me”, the second one says: “Now, this custom column will append this query string“.

    I my case, the third hook almost done nothing, because I created a column called “menu_order”, a native attribute from WP (used in Pages context). So, read the post above to deal with your specific case.

    I hope it helps!

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘Custom column, order by option’ is closed to new replies.