Skip Navigation

[Resolved] Sortable table headings

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a problem where my table headings are not all sortable, specifically two columns based on a custom date field.

Solution: Check the syntax for the wpv-heading shortcodes in the table header cell. Custom fields should include the "types-field-" prefix before the field slug.

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Jackie 5 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1214487

Hi there,

I'm working on a catalog for a Continuing Education department at a college of art and design. Using the Loop Wizard, I've created a view with a table that has five columns:

+ Course Name [String]
+ Course Number [String]
+ Category [String]
+ Start Date [Date]
+ End Date [Date]

My table's columns are supposed to be interactive and, when clicked, sort the table in either ascending or descending order. The columns with a data type of "String" are in fact sortable, but the columns with a data type of "Date" are not. Can I make my table sortable by the date fields?

You can see the table on this webpage:

hidden link

Thank you!

Saul

#1215153

Hi, are these start and end dates custom fields? Are they created in Types? Are the start and end dates applied to the posts shown in the table results (as opposed to some related post)?

If the answer to those questions is "yes" then it should be possible to sort based on those date columns. If the answer to any of those questions is "no" then it's a bit more complicated and I would have to take a closer look.

#1216672
start date ascending order - not working.png
Screen Shot 2019-03-18 at 21.07.51.png

Christian,

Thanks for your response. The answer to all of your questions is indeed "yes." Here's the code for the table header snippet:

		<thead>
			<tr>
				<th>[wpv-heading name="post-title"]Course[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-course-number"]Course No.[/wpv-heading]</th>
				<th>[wpv-heading name="post-taxonomy"]Category[/wpv-heading]</th>
				<th>Start Date</th>
				<th>End Date</th>
			</tr>
		</thead>

I've attached a screenshot for greater context (Screen Shot 2019-03-18 at 21.07.51.png). Note: when I added a [wpv-heading] to the Start Date field, the sort order was crazy. I've attached a second screenshot (start date ascending order - not working.png).

S

#1217056

Okay you'll have to apply a wpv-heading to the Start Date column header, as well as the End Date header. Otherwise, they won't be sortable. Verify the start and end date field slugs in wp-admin to be sure you're using the correct spelling and punctuation in the slug names. If that's not the problem, try a few troubleshooting steps:
- Temporarily deactivate all plugins except Types and Views, activate a default theme like Twenty Nineteen, and test again
- If the problem is resolved, reactivate your theme and other plugins one by one until the problem returns
- If the problem was not resolved, I'll need to take a closer look. Please provide login credentials in the private reply fields here.

#1221398

I found the solution to the problem. Here's the wrong code I was using for the header:

<th>[wpv-heading name="course-start-date"]Start Date[/wpv-heading]</th>

Here's the correct code:

<th>[wpv-heading name="types-field-course-start-date"]Start Date[/wpv-heading]</th>

I manually entered the name attribute, and it takes a specially formatted name, not the custom field slug. Christian, is there a reason why the [wpv-heading] shortcode uses a variant of the custom field slug instead of just the custom field slug as is customary elsewhere in the interface?

Saul