Support Forum
Support › MB Relationships › Relationships - change order of posts returned by shortcode
I'm using this shortcode - how can I display the returned posts alphabetically?
[mb_relationships id="therapists_to_modalities" direction="to" mode="ul"]
Hi Max,
Currently, it's not supported in the shortcode (although it's available via PHP when you use WP_Query and set the orderby
parameter). We'll add order parameter to the shortcode soon.
Ok thanks. Can you provide an example in PHP? I didn't see it when looking.
Hello Max
To sort in alphabetical order please check the link Display in alphabetical order
Thanks. I had meant an example of using WP_Query and relationships, but I found it on your site. I'm using this updated code, however posts are still not alphabetized - can you explain why not?
Code: https://cl.ly/76ea47f4f474 (This forum was encoding characters wrong)
Link: https://www.massagetherapypaloalto.com/modalities/clinical-deep-tissue-massage/
Hi Max, the order
and orderby
should be outside of relationship
param, as they're arguments for WP_Query
. Please try:
$connected = new WP_Query( array(
'relationship' => array(
'id' => 'therapists_to_modalities',
'to' => get_the_ID(),
),
'orderby' => 'name',
'order' => 'ASC',
'nopaging' => true,
) );
Hi - Unfortunately something is still wrong. I'm using that code and the order has not changed. To rule out any other factors I disabled all other plugins and am using the 2019 theme here:
https://staging-massagetherapypaloalto.kinsta.cloud/modalities/clinical-deep-tissue-massage/
Relationship code: https://cl.ly/d4dd24cd5582
Display code: https://cl.ly/991ead53fdc7
Thank you.
Hi - Hoping for a response since this is on a live site. Thank you!
Hi, Max
I checked the code you sent and found it working normally
demo check: https://www.youtube.com/watch?v=ANgWu_NEjKM&feature=youtu.be
code check : https://ghostbin.com/paste/xtz72
thank you!
Thank you - the demo appears to work fine. Could the difference be that you based that on a post / page relationship, and mine is based on two custom post types? That's the only difference that I can see.
Hi Max,
Yes, I have changed post_type to be able to correctly check your issuse.
But the issuseI want to say here is that your code is sent, it runs normally.
So your unscheduled error may be due to another issuse, so you can check back.