Skip Navigation

[Resolved] Table column sorting suddenly stopped working for no reason

This support ticket is created 8 years, 1 month 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 2 voices.

Last updated by Beda 8 years ago.

Assisted by: Beda.

Author
Posts
#376997

I am trying to: Sort table columns, both numeric and single line

I visited this URL: My site is not available for viewing

I expected to see: I expected the fields to sort from highest to lowest and visa versa

Instead, I got: sorts them randomly

#377117

It might be due to the nature of the Fields in there.

WordPress uses to read all of them as STRINGS and not NUMBERS.

So if you have a Numeric Field you can only sort this according numeric sequence if you use a Custom Query, as in Views it does.

If this numeric field as example is used anywhere else where a WordPress Query is used, it will most probably do something like this:
1
10
11
12
2
3
...
9
1
10
...

This is because it would query by string and not as numeric value.

But these are assumptions, I need to see this happening or at least some steps on who to reproduce it locally, in case this is done in a View Query Filter.

Thank you

#377395
Post-fields.jpg
View.jpg

Hi Beda,

I am not really sure I understand your reply, below is the code I'm using.

LOOP OUTPUT

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%">
      <thead>
        <tr>
            <th></th>
            <th>[wpv-heading name="min-loan-amount"]Min Loan[/wpv-heading]</th>
            <th>[wpv-heading name="max-loan-amount"]Max Loan[/wpv-heading]</th>
            <th>[wpv-heading name="min-term"]Min Term[/wpv-heading]</th>
            <th>[wpv-heading name="max-term"]Max Term[/wpv-heading]</th>
         <th>[wpv-heading name="representative-apr"]APR %[/wpv-heading]</th>
           <th></th>
        </tr>
    </thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="Loop item in Long-term loans"]
			</tr>

           <tr>
    <td colspan="5" class="detail-row">[mk_toggle style="fancy" title="More detail"]<div id="quid-product-example">[types field="example"][/types]</div>[/mk_toggle]</td>
    <td colspan="2">[wpv-woo-buy-or-select]</td>
  </tr>
          <tr>
            <td colspan="8"><div class="loop-line" ></div></td>
            </tr>
          
         </wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

TEMPLATE FOR THE VIEW

<td><div class="quidproduct-image">[wpv-woo-product-image]</div>[wpv-post-title]</td>
<td><p class="quid-product-title">Min Loan</p><div id="quid-product-data"><p class="quid-product-data">[types field="min-loan-amount" format="£FIELD_VALUE"][/types]</p></div></td>
<td class="greyline"><p class="quid-product-title">Max Loan</p><div id="quid-product-data"><p class="quid-product-data">[types field="max-loan-amount" format="£FIELD_VALUE"][/types]</p></div></td>
<td class="greyline" class="greyline" class="greyline" class="greyline"><p class="quid-product-title">Min Term</p><div id="quid-product-data"><p class="quid-product-data">[types field="min-term"][/types]</p></div></td>
<td class="greyline" class="greyline" class="greyline"><p class="quid-product-title">Max Term</p><div id="quid-product-data"><p class="quid-product-data">[types field="max-term"][/types]</p></div></td>
<td class="greyline" class="greyline"><p class="quid-product-title">Representative APR</p><div id="quid-product-data"><p class="quid-product-data">[types field="representative-apr"][/types]</p></div></td>
<td class="greyline"><p class="quid-product-title">Same-day Transfer</p><div id="quid-product-data"><p class="quid-product-data">[types field="same-day-transfer"][/types]</p></div></td>
#377441
Sort DESC by Single Line.png
Sort DESC by Numerical .png
Sort ASC by Single Line.png
Sort ASC by Numerical.png
Original Output.png

As long your field is a numeric Field and the values are numbers, this will sort correctly and not random.

Also a string like a Single Line Field will be sort by (it's first) alphabetical letter order.

I post below the Code you need to use for this to work and a Screenshot on what you will get.

This assumes a View, that Queries a Post Type and orders it by Post Date DESC, in the Query Filter (Order By) options, and a Table inserted by the GRID Wizard in the View Loop.

It uses 2 Custom Fields created by Types, a Numeric and Single Line one.

LOOP:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%">
		<thead>
			<tr>
				<th>[wpv-heading name="post-title"]Post title[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-line"]line[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-number"]number[/wpv-heading]</th>
			</tr>
		</thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="Loop item in Posts View"]
			</tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

The Content Template that automatically get's assigned to it:

<td>[wpv-post-title]</td>
<td>[types field="line"][/types]</td>
<td>[types field="number" format="FIELD_VALUE"][/types]</td>

See the screenshot on the outposts, once sort by Number (ASC and DESC) and once by Single Line (ASC and DESC)

Thank you.

#377591

Hi,

I cannot get it to work whether I use Numeric or Single Line fields.

Perhaps as an alternative I can create a dropdown menu at the top using Parametric Search.

How would I create a dropdown that can sort by "lowest to highest" of a specific custom field?

#377739

No, Views does not yet support Front End Sort/Order by features, this is in the ToDo Lists but not implemented.

And the Table must work, it does locally, so it must on your Site as well.

I require temporary access (WP-Admin and FTP) to your site
- preferably to a test site where the problem has been replicated if possible -
in order to be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ I would, if possible, need access to a site where only a minimal set of Plugins and a default theme is active.
This to avoid eventual compatibility issues with other software.

✙ I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site, as well as change code and create Dummy content.

This is also a reason the backup is really important

✙ Please add the Links to:

- The Views Edit Screen

- The Page/Post where you insert the View

- The corresponding Front End Page/Screen

Since you seem to not yet be online with the site, I can not (unless you upload this all to a server) see and help with this.

What I can do in this case is as example create a Example instance on our Discover WP Servers where you can login afterwards and see this working.

Would this help to you?

Or would you be willing to upload your Site?

Either way I enable the private form and expect your opinion on what you prefer

Thank you

#379517

And I am re-eanbling the Private form therefore, to be ready for you once you have the Details

Thank you

#379948

This Login URL returns me a 404

Can you provide me the path to login to your website?

Have you customized the WP Admin and Login URL's?

Thank you

#380478

I had added these, but now I recognized i had a typo in it.

Thanks for pointing me to it.

Now, I read in the Title, "Suddenly stopped working"

As I elaborated on the first reply, this is not expected to work, and I am somewhat confused that you state, it worked before and suddenly stopped working.

As you will see, as example "Credit Check" works fine.
"Representative APR" does not.
This is simply because this Field is not numeric, and does not hold sortable values.

There is also a Feature request in Views to add DECIMAL numeric value sorting or querying.
This will be solved in a future release, but right now we can not provide a workaround for this.

Also you add things like "£FIELD_VALUE" in the Custom Fields output.
This will not work, how should a Query know which "£" comes first?

Are you sure this ever worked like this on your website?
It is so far not expected to work.

Numerical Field Types will be sort fine by number, and Single Lines by string-

Does that help you to solve the issue?

Thank you

#381135

Hi Beda,

please have a look at the following page hidden link
the column titled MIN LOAN has simple numeric values. I have inserted the pound sign using a different method and have tested with and without the pound sign but the columns are still not sorting.

Link to View:
hidden link

You can check the custom field setup for that field here:
hidden link

Also, if you go to the Post Field Control there seems to be a custom field called "wccpf_min_loan_amount"
hidden link

Regards, Mark

#381698

In the Control Section you have a 3rd party Custom Field which is a text field.

This is not the same field as in Types > Custom fields > your_group > Min Loan Amount.
That field is numeric, has a different Slug and is not the field which you see in the Control Interface.

In the View you filter by this last Types Field min_loan_amount, and in the Products (as example "Mr Lender") you populate the Types field with the numeric value 100.

So far so good.

Since you use much Custom HTML in your View and I can not debug your Custom Code, I went ahead and created a View + Page where I show you that this Table Sorting is working.

The page is here:
hidden link

This is the View (very simple and basic):
hidden link

You can now adapt this View or copy it over to your exiting View to make this Sorting work.

I created the View with the GRID Wizard, so to ensure a "clean" code.

Thank you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.