Skip Navigation

[Resolved] Views multiple ordering : by field then random

This support ticket is created 3 years, 11 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 3 voices.

Last updated by Wilhem 3 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1935035

Tell us what you are trying to do?

Order results of a view by a custom field then random with all the post with the custom field == true appears first, than all posts random and limit 8 results.

1 : custom field == true
2 : custom field == true
3 : custom field == false / Random ID
4 : custom field == false / Random ID
5 : custom field == false / Random ID
6 : custom field == false / Random ID
7 : custom field == false / Random ID
8 : custom field == false / Random ID

When I try it in views settings, only the custom field == true shows

Thank you in advance !
Best regards,
Wilhem

#1935219

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2021-02-05 at 14.15.47.png

When you write "custom field==true" and "custom field==false", what exactly do you mean?

That the custom field is a string and either has the string value "true" or the string value "false"?

If instead you mean that for custom field==false the custom field has no value, then it is expected that such results are excluded from the results (screenshot).

That is how WordPress queries work (it's actually how the underlying mySQL query works).

If you order by some field, then only posts that actually have a value for that field will be returned. If you want them to be included in the results, you must give them some value.

#1935491

Hi Nigel,

"custom field==true" and "custom field==false"
was an example, in my case it's :

wpcf-f-promote
this field is a checkbox 1 if check / 0 if not

If instead you mean that for custom field==false the custom field has no value, then it is expected that such results are excluded from the results (screenshot).
>>> Meaning, 0 seems not to be stored ?
>>> Ok right ! That's a new field, so the old post don't have a value for that field. I have to update all post.

I will try to update all post and keep you informed

#1935549

Well it's working now.
Do you a simple method to populate the new field wpcf-f-promote with value 0 to all previous post ?
Best
Wilhem

#1935685

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Wilhem,

Checking on this ticket here, happy to see that it is now working, however no we do not have a method for you to be able to update all your posts with a 0 value.

You will need to go through the posts and update them individually so that the custom field meta is stored in the database.

Thanks,
Shane

#1937737

Thanks a lot, My issue is resolved now. Thank you!