Hi Team,
I have a Classic View that displays a CPT in a table style.
One of the table columns includes a value that comes from a related (child) post's custom field(date type).
Is it possible to sort the table rows (like we usually do by clicking on the table heading) by taking the child post's custom field value in mind?
Currently the sorting is just able to differentiate between posts that have that child post's field filled in, and those that are empty.
However I'd like to get that going properly. I tried different date formats and even "raw" (the unix timestamp), however the sorting doesn't seem to have an idea of the actual values.
Best,
D.
Hello,
Toolset Views/Blocks plugins are using WordPress built-in class WP_Query to query posts, so you can sort the result by post fields you are querying(Parent post type), can not sort result by fields of other post type(child post type)
More helps:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
‘meta_value_num‘ – Order by numeric meta value (available since version 2.8). Also note that a ‘meta_key=keyname‘ must also be present in the query.
Hi Luo,
I have managed to solve the issue myself. I have changed my view to query the child post instead, and sort the table based on it's custom field. Then I have queried the rest of the fields that I require by pulling them from the parent post fields.
Thanks anyway!
D.