Skip Navigation

[Closed] Change order of relationship-fields in custom post type.

This support ticket is created 4 years, 8 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
- 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+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 4 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#1591765
toolset-sections.jpg

Tell us what you are trying to do?
I have looked through numerous posts and can't find any way to affect the order that the relationships show up in my custom post type. I'm not talking about the common problem of sorting content within the relationship, but rather the relationships themselves. For example, I have a one-to-many link for posts allowing my "section" custom post type to have multiple posts in it. I have a pages relationship for the same thing with pages. But I have a one-to-one relationship for Cover Pages. These are unique single pages that will be displayed at the beginning of my section output. Right now, when I create a new Section post, it asks for Section-Posts, Section-Pages, then Section-CoverPage. I would pref that it asked for Section-CoverPage first, then Pages, then Posts. Is this possible? What order are the relationship fields displayed in? If I delete all my relationships and add them back in the order I want them, will this change the order they are asked in a new Section CPT?
What is the link to your site?
Just starting this site and trying out relationships so there's nothing up to look at yet.

What would be nice is if the dashboard for relationships allowed you to order them the way that Pages can be ordered by drag and drop.

#1592435

Nigel
Supporter

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

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

Hi Jason

WordPress metaboxes are designed to be managed on a per-user basis, so any user can according to their preferences drag and drop the metaboxes into their preferred order, close ones they are not interested in seeing normally, etc., so that every user may see something different according to their needs.

So you could simply re-order the metaboxes for the relationships when editing a post and it would be reflected on all such posts, but only for you.

I'm guessing you want a different experience, namely that all users see the same—particular—order.

You would need to use a somewhat obscure WordPress filter for this, where you can modify the order and apply it to all users.

The filter is a dynamic filter, get_user_option_{$option} (https://developer.wordpress.org/reference/hooks/get_user_option_option/).

You can see an example of it being used in the do_meta_boxes documentation comments: https://developer.wordpress.org/reference/functions/do_meta_boxes/#comment-2090

I dumped the $order attribute to my logs for an idea of what to expect, and found the metaboxes for my two relationships applied to the post type in question in the advanced section (for project-tasks and project-posts), e.g.

[20-Apr-2020 09:09:17 UTC] order: Array
(
    [side] => views_template,submitdiv,statusdiv,colourdiv
    [views_template] => 
    [normal] => wpcf-group-project-fields,commentstatusdiv,commentsdiv,slugdiv
    [advanced] => types-related-content-project-post,types-related-content-project-task
)

So that's where you would need to set the required order.

Are you able to do that?

The topic ‘[Closed] Change order of relationship-fields in custom post type.’ is closed to new replies.