Skip Navigation

[Resolved] Sorting search results

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

Problem:
In my View's Loop I have a sortable table with Custom Fields.
Some Custom Fields, when sorted, work properly, means only the existing entries show.
Some other fields thou, even show if they are empty, if you sort the table by them.

Solution:
The field is not empty, this is the only explanation.
Usually, this can happen due to a database corruption or someone added empty spaces to the fields and saved them.

Please try to re-save all affected posts and make sure no value is in the empty fields.
For this, first add a value, save it, then remove the value and re-save it.

This is an exception, usually visual empty field are really empty, but it can happen that the fields hold not visible values.

This support ticket is created 6 years, 9 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
- - 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 JosV9233 6 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#608202
Pict1_not-sorted.jpg
Pict2_begin-abo.jpg
pict3_06-nummer.jpg

Hello,

I have a view with results from a search. (Pict 1). When I sort the dates 'Begin abo' and 'Eind abo', the result displays only the records with the date which is sorted. (Pict 2).
When I sort '06-nummer' or 'Provider' all the records are displayed, also those with empty fields. (Pict 3)

I prefer the situation where only records are displayed with data in the field.
Why is this difference and how can I force the 'only data' result?

Note: 'Klant naam' and 'Geb datum' come from the user post type and will not sort. The client is happy with that.

#608238

When I test this, I see that the Table sorting will exclude all entries where the currently sorted value is missing.

It does not matter wether this is a Post Meta or Custom Field and the difference of Custom Fields also does not matter.
In any case, I will see only the results that have all the sorted by field filled out.

Eventually you use taxonomies instead of fields? Those won't work properly in these tables.

I was not able to replicate the problem with Fields and Post Title (I used a date field, a Phone Number field and the Post Title)

Can you exactly show me how to replicate it, or send me a copy of this site so I can see how this happens?
https://toolset.com/faq/provide-supporters-copy-site/

#608247

Beda can you give me a private reply?

#608784

Beda, tell me how I can send a copy. I do not want to do it for everybody to see.

#608826

I am sorry the delay.

1. Private reply can only be activated by me.
I re-activated it so your next reply is private.

2. No Link in this forum is public unless you are author of the ticket or supporter.
(So, Even without private reply your link would be protected)

Everything should be ready now.

#608865

You have probably added headings manually, because the Slugs you use are wrong:

<th>[wpv-heading name="geb-datum"]Geb datum[/wpv-heading]</th>
<th>[wpv-heading name="types-tijdelijk-06-nummer"]06-nummer[/wpv-heading]</th>
<th>[wpv-heading name="types-provider-nu"]Provider[/wpv-heading]</th>
<th>[wpv-heading name="types-field-ingangsdatum-abo"]Begin abo[/wpv-heading]</th>              
<th>[wpv-heading name="types-field-einddatum-abo"]Eind abo[/wpv-heading]</th>

While it should be:

<th>[wpv-heading name="types-field-einddatum-abo"]Einddatum abo[/wpv-heading]</th>
<th>[wpv-heading name="types-field-provider-nu"]Provider oud[/wpv-heading]</th>
<th>[wpv-heading name="types-field-puk2"]PUK[/wpv-heading]</th>
<th>[wpv-heading name="types-field-tijdelijk-06-nummer"]Tijdelijk 06-nummer[/wpv-heading]</th>

Etc.

Notice the "types-field-" prefix?
You miss it in your both faulty Fields "provider-nu" and "tijdelijk-06-nummer".

Please use only the GUI (Loop Wizard) to insert such structures.

What I also see is that you pass URL arguments to this table, and as well Text Query with Relevanssi.

What is to mention is that if you pass hardcoded URL arguments, they will always apply to the output.

Anyway, after fixing the loop and using the correct syntax, the sorting will output the right results - but as said, this is a sorting, and any query applied to it has preference.

#608870

Well, on the duplicator this solved the issue.

I still see that you use no prefix on some fields (geb-datum) - I assume this is a Types field too.

The query you have might influence the results.
If you still get unexpected results after re-creating this loop with the Wizard (not manually) then I suggest to remove the filters and recreate them to see when the issue comes back, but in my local install I had no issue with this when I used a new loop.

Could it be that you use a cache mechanism on your server?
This could affect the changes (by not applying them immediately)

If you still see this issue after above steps, please can you grant me full access to the site where you develop, and a minor permit to edit the View in question?
Please also share the link to the View directly here in the forum.

Thank you

#608923

The link:

hidden link

#609377
ERROR: The password you entered for the username toolset is incorrect. Lost your password?

Can you revise the provided log in data and add them again to the next private reply?

Thank you!

#609422

This time I got in, thank you.

On a clean install, this works fine with all kind if fields you use.
The empty results are not shown, and the ordering works fine.

I saw the problem on your site and deployed it again locally.

Clearly it seems those fields are interpreted as not empty, since if you order by "Provider" for example you get 8 results, but if you list all results they are 12, which means some are removed, correctly, but others, apparently empty, are still considered populated by Views.

I think I must have overseen these 2 fields when I tested last time on my local, as now I found the real issue for this problem.

Somehow in the Database empty values got saved for those posts you see there - but which we both agree should not appear when sorting by the field.

You can check your data base for the post meta "wpcf-06-nummer", which is saved several times empty against those faulty posts.

The way I solved this, was to edit the single posts and add a value to the field, save, and then remove (not add an empty space, but delete the content) the content and re-save again.

This solved the issue, the field is now really empty and not saved as a empty space in the Database.

You will see that you have several such empty fields stored in the Database, which can be removed as well directly in the database (but for that please perform a full database back-up first)

This solved the issue for good locally.

The problem is that some of those fields save an empty value in the database, most likely a space.
Eventually this has happened by mistake or a database misconnection could be the reason as well.

Can you give this steps a try?
(You can simply edit the fields in the relevant posts, add some value, save, remove it and save again)

Please let me know if this now solved the problem

#609485

Hi Beda,
Your solution solved the existing problem. I hope it will not come back in the future.
Thank you very much for going through all this trouble.
Concerning this site I still have a question about a relationship-srtructure which I will voice in a new support ticket.
Thanks again,
Jos