To follow up on @rock3t’s comment, do you really have to query the backend whenever a user clicks on a column header?
Have you looking into using the jQuery tablesorter? It allows an end-user to sort an HTML table by doing DOM manipulations.
I’ve never used it in a WP project, but I have used it extensively in other projects I’ve built and it works great. It’s very configurable, so I’m sure it will satisfy your needs.
tablesorter is not one of the jQuery plugins included with WP Core. So you’ll have to download it (from the above link), include it in your plugin/theme somewhere and enqueue it. Then, enqueue a simple JS file that would like something like:
(function ($) {
$(document).ready (function () {
$('#id_of_your_table').tablesorter ({widgets: ['zebra']}) ;
}) ;
})(jQuery) ;
You can read more about how to use tablesort in their docs, including various other parms to the tablesorter()
method.
Related Posts:
- WP_Query order by custom field, then randomly order some of results
- How do I set the default admin sort order for a custom post type to a custom column?
- Using meta_query, how can i filter by a custom field and order by another one?
- How to order adjacent posts (prev / next) by custom field value?
- Filtering a WP_Query meta_query by numeric values isn’t working
- Sorting a query by custom field date
- Custom Taxonomy Template Post List with Sort Order
- Automatically fill custom field value on post publish/update
- Filter a custom field based on selection of another custom field (ACF) [closed]
- ACF Relationships in Custom Post Type Permalink
- WordPress Search documentation: how to improve search query using taxonomy terms, custom meta fields?
- Use Custom Post Type as Custom Field
- How to Sort Custom Field Admin Column by Date
- How to Sort by Date When Using d-m-Y Format
- Display posts if a custom field value is equal to another custom field value
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Sort by two dates. Default entry date and custom field if present
- Get Custom Field Values by Another Custom Field in WordPress
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Query Custom Post Types by date (custom field) range
- Custom Post type and Custom Field WP_Query
- How to change post featured image using a custom field of category?
- Sorting custom post type columns with external data and without meta values
- Retrieve value of a category’s custom field
- How can I dynamically add a post to a custom post type which uses a custom field?
- Bulk Update Custom Fields for Custom Post Types
- Query custom post type with ACF Date
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Order Custom Post Type by Custom Field Value
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Multiple Frontend Filters Using Advanced Custom Fields
- Integrate Custom Post Type Events into Calendar
- Displaying custom field according to date
- WebP Fallback for Inline Background Image in Style Attribute
- Query based on custom fields start and end date
- How to get a custom type post data when it has a connection with another custom type post?
- Sort a custom post with ACF: Date Picker & Display Featured!
- List of users that clicked a ‘Join’ button at single post
- How to inherit field value from parent post into in child / sub post
- Custom Post Type page sorts differently on different environments
- Custome fields not displayed
- Sort custom post type by most current date picker
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- How do I replace the post title with a custom field?
- Sum and count of custom field values
- Group by custom field value (start and end times)
- Custom post types, disable fields
- Make a custom column sortable by a value from a different custom post type
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Excerpt length: get first paragraph
- How can I sort the order of multiple custom field values in a custom post type?
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- ACF – Retrieve custom taxonomy from a relationship field
- Create if else for post types in WP_Query ‘post__in’ values
- Sort custom posts by date and then by taxonomy
- Display Custom Field or Custom Taxonomy in front page /post/product
- How to access repeater field of a custom field?
- Filter posts by their related field’s custom field
- filter using custom fields
- Autofill advanced custom field with user data
- Advanced search form with multiple custom fields
- sorting in wp query based on custom field value
- How do I display specific custom posts, and how do I edit a post’s singular page?
- Fixed custom fields depending on posttype/category
- Automatically convert standard posts with custom fields to custom post types
- 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
- Can’t pick up a field created with Advanced Custom Fields
- Get month and day from a Date Picker custom field
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- How to show animal lineage/pedigree in WordPress?
- ACF – Query relationship without ID
- Retrieve a post with its ACF repeater fields in wordpress
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Display ACF object field data using Elementor Custom Query
- Sort CPT by taxonomy AND THEN by custom field
- Post object GUID adding http:/
- Custom Sort Order for Custom Post Type Taxonomy
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Sort Posts Best Practice
- Assign Taxonomy Based on Custom Field Value
- Custom column sorting in WordPress admin post table
- Assigning the same custom meta box to multiple post types
- echo selected value from dropdown
- Creating a “glossary” of WordPress posts of a specific post type
- How can I see a list of products that I have set to outofstock through a custom field check box?
- delete duplicate meta_value with same post_id
- Adding a location field to buddypress activity
- Changing default admin column sorting to an ACF Date Picker field
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- I want to create a metabox under custom taxonomy
- How do I add custom fields to posts without having to manually add everytime I post?
- Function that get ACF fields value before saving