Support

Account

Home Forums Backend Issues (wp-admin) Sort custom column in table by ACF link/oEmbed Reply To: Sort custom column in table by ACF link/oEmbed

  • I’m not an expert on this but I did something similar – added columns for a CPT and made them sortable……so a couple of suggestions (questions?) come to mind:

    1. I assume you specified that the (new) columns are sortable using the hook “manage_edit-{cpt}_sortable_columns’? I have three added columns for a ‘deals’ CPT so I made those columns sortable like this (example):

    function my_deal_sortable_columns( $columns ) {
    	$columns['expires'] = 'expires';
    	$columns['author'] = 'author';
    	$columns['resort'] = 'resort';
    	return $columns;
    }
    add_filter( 'manage_edit-deal_sortable_columns', 'my_deal_sortable_columns' );

    2. Perhaps you need to add the meta_type to your orderby statement? I need the ‘expires’ column to be sortable based on the value which is a date, not a string, so I had to add the meta_type, like this example:

      $orderby = $query->get( 'orderby');
     
        if( 'expires' == $orderby ) {
            $query->set('meta_key','booking_date_end');
            $query->set('orderby','meta_value');
    		$query->set('meta_type','DATE');
    		$query->set('ignore_sticky_posts',true);
        }

    Hopefully this may be enough to help, if not post back and maybe I can be of more assistance. Good luck!