Skip Navigation

[Resolved] Many to many sorting by custom field problem

This support ticket is created 6 years, 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 5 replies, has 3 voices.

Last updated by maciejL 6 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#591348

Hello,
My problem is in results sorting:
Many to many.
People ("osoby" type) belongs to groups ("samorzad" type). Przynaleznosci ("appearance" type) is the main type with osoby and samorzad as parents.
Przynaleznosci type (slug: appearance) has custom field "rola" - person's (osoby) position in the group (samorzad) hierarchy.
I'd like to sort results by "rola" custom field (view ID: 319).

But whatever I set in sorting option in the view settings, it seems to not working at all. It always sorts by post_date desc. Even if I give a parameter orderby within wpv-view tag.

Groups: hidden link
Single group with wpv-view tag in template (ID: 318), displaying persons (osoby): hidden link
(view ID: 319)
The last view I'd like to sort by Field "Rola".

Please ask, if something is not clear enough.

Kind regards
Maciej

#591449

Dear Maciej,

Thanks for the details, please check this:
Edit the content template "Szablon dla Samorząd - pojedyncza komisja":
hidden link
You are using below Views shortcode:
[wpv-view name="osoby-ktore-sa-w-komisji" cached="off" orderby="post_title"]

The attribute "orderby" will override settings in the view, so you can change it as below, and test again:
[wpv-view name="osoby-ktore-sa-w-komisji" cached="off"]

#591489

Hi Luo,
unfortunately, as I wrote before - "Even if I give a parameter orderby within wpv-view tag" - it doesn't have impact at all.
I'm not really sure, but the problem could apear after install "Intuitive CPO" (Custom Post Order). But now, even if the module is off, sorting options don't work.

#591515

So it should be a compatibility problem, please check these in your website:
1) deactivate other plugins and switch to wordpress default theme, and test again
2) If the problem still persists, please provide a database dump file (ZIP file) of your website in below private detail box, I need to test and debug it in my localhost, thanks

#591523

Nigel
Supporter

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

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

Hi Maciej

I looked at your site and can see the problem (I removed the sort attributes you had added to the shortcode where you inserted the View on the content template for samorzad which I assume you were using for testing).

You already have Query Monitor installed, and I can see that the sorting preferences for the View are not being added to the SQL query, though I don't know why.

I set up a local test site to double-check what to expect and it was working correctly on my test site, using a radio field to sort by.

I don't know if this is a live site so I am reluctant to change anything else.

The first thing I would like to do is to disable all of your non-Toolset plugins and to switch theme to twentyseventeen to see if anything may be conflicting with the View query.

Could you please try that and let me know if it affects the ordering?

Let me know how that goes and then I'll see how to proceed.

#591562

Thank you Luo, thank you Nigel!
1 simple check - theme change and it works. However, my "Widgetize pages" widgets are gone, after this change. But I can recover my db from yesterday (strange behaviour, it should not disapear ???? ).

I found some code in functions.php which had to sort post on homepage, but the "if rule" was not correct:

add_action( 'pre_get_posts', 'my_home_ordering' );
function my_home_ordering( $query ) {
    if ($query->is_home() ) {
                $query->set( 'orderby', 'date');
                $query->set('order', 'DESC' );
    }
}

Should be is_home() without "$query->".

Thanks again for inspiration!

Regards
Maciej

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