Autosort a Category by posts Featured Image Title

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

The Automatic Order functionality along with Custom Function it’s a very powerful tool to customize the sort of a give area by very specific criteria. As specified at the filter return a list of all posts within the section / query on which different operations can apply.

In the following example, a sort list is ordered by the posts Featured Images Title. After creating a simple sort as show at chose Automatic Order, then Custom Function. As parameter, use function name which should be included within theme functions.php or a custom plugin, in this example custom_sorting_function_featured_file

function custom_sorting_function_featured_file($post_list, $sort_view_id, $orderBy, $query)
        $list_map_feature   =   array();
                foreach($post_list  as  $object_id)
                        $thumbnail_id = get_post_meta($object_id, '_thumbnail_id', TRUE);
                        $feature_post   =   get_post($thumbnail_id);
                        $list_map_feature[basename($feature_post->guid)]    =   $object_id;
                //sort the dates ascending
                $post_list  =   array_values($list_map_feature);
                return $post_list;