You can sort the results based on your custom table data by applying a custom filter to your existing query using the “posts_orderby” hook (untested example code):
add_filter('posts_orderby', 'edit_posts_orderby');
function edit_posts_orderby($orderby_statement) {
$orderby_statement = "views DESC";
return $orderby_statement;
}
Source: based on user comment at:
https://developer.wordpress.org/reference/hooks/posts_orderby/
Related Posts:
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- How do I set the default admin sort order for a custom post type to a custom column?
- Make custom column sortable
- Using meta_query, how can i filter by a custom field and order by another one?
- group search results by post type?
- register_post_type sort order by title by default
- Drag n Drop Post Order for multiple Custom Post Types
- Sort custom post type list table by display name of a user id stored as post meta value
- Custom sortable columns ordered by meta-value?
- How to order adjacent posts (prev / next) by custom field value?
- WordPress post sorting with AJAX
- Ordering posts by custom taxonomy in admin area
- Custom Post Type, WP_Query and ‘orderby’
- Filter admin columns by custom post field value
- Sorting a query by custom field date
- Custom Taxonomy Template Post List with Sort Order
- Ordering Posts List By Taxonomy Terms?
- Column sorting with emtpy meta values
- Number of pages – multiple (custom) post types
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- how to sort post in admin column by recently
- Custom Post type sort order not working in the admin area
- How to sort a table of custom posts by column containing custom field
- Alphabetical sorting of custom post type – one letter per page
- sort events based on event date custom field
- How to Sort Custom Field Admin Column by Date
- How to Sort by Date When Using d-m-Y Format
- Sort Posts Best Practice
- Custom Post Type sorted by Title
- How to add new tab to admin list of posts and handle result list
- Sort by two dates. Default entry date and custom field if present
- How do I sort a custom post type admin column using two meta keys?
- Custom-post-type-archive: posts sorted/filtered by year?
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- query_posts with a custom post type, a meta_query and sorting by post date?
- sort order for a custom post-type [closed]
- Sort admin area by custom Event Date field
- Custom post type ‘orderby’ => ‘meta_value’ not working
- How to rank custom post type from score points
- Sorting multiple custom post types without a meta key/value pair by sort order
- Order By Post Type ThenBy Taxonomy
- Combining sorted and random CPT
- Sorting custom post type columns with external data and without meta values
- Default sort on admin columns with meta date hides draft posts with empty date value
- Categories sorting
- Wp_query: sort by PHP variable
- Crafting WP_Query array, sort by date
- WP_Query order by custom field, then randomly order some of results
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Custom post type, organized by categories
- WooCommerce sort products by the actual product width(not the shipping width)
- Sort and filter custom post type posts by custom taxonomy
- WordPress posts page for customer filtering and sorting along with category filter
- manage_edit-{post_type}_sortable_columns sorts, but wrong!
- Sort entries by date mixing two post types
- Order a custom post type admin screen by a second custom post type title
- How to sort posts in a custom post type by title in ascending order by default?
- sort post types by amount of views
- Custom post type sorting: alphabetical order
- Sort a custom post with ACF: Date Picker & Display Featured!
- Sortable column containing numeric values for Custom Post Type at WordPress Backend
- Custom Post Type page sorts differently on different environments
- Sort custom post type by most current date picker
- Creating a “glossary” of WordPress posts of a specific post type
- Sort results without WP_QUERY?
- Make a custom column sortable by a value from a different custom post type
- sort by name (slug) custom post type
- Sort column on meta key and meta value
- Sorting custom post types in edit.php : Post disappear
- Custom loop request based on custom field
- What’s an easy way of sorting custom post types manually?
- How can I sort the order of multiple custom field values in a custom post type?
- Sorting the Loop by Taxonomy Value
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Sort custom posts by date and then by taxonomy
- Sort custom post type by custom datepicker instead of filtering
- How to sort by multiple values in a nested WP_Query
- Custom post type order by post_title
- How to sort post category using its Description
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Wp Query sort order from custom MetaBox
- Using Orderby and meta_value to order natural/alphanumerical
- sorting in wp query based on custom field value
- week days sorting based on starting day
- How to sort custom post’s category by id from the theme’s function.php?
- Group/list/sort custom post type posts by date in tabs from acf datepicker field
- Grouping and paging CPT events by month with custom field date
- Ordering Posts List By Taxonomy Terms?
- Custom post type taxonomy not sorting correctly
- How do I sort post listing by child post count?
- Make custom post type column sortable
- sort custom post type by display name
- How can I sort posts ascending by post title for a specific post type, but on a category archive template?
- Test if a Category contains certain Custom Post Types
- Sort CPT by taxonomy AND THEN by custom field
- Custom order of CPT posts by title, in wp-admin area by default
- Sorting by Title for Post Archive Categories for Custom Post Type
- Submit post and upload image from front-end
- Using Custom Fields in Custom Post Type URL
- Why is the »_builtin« parameter not advised in »register_post_type()« for custom post types?