Skip Navigation

[Resolved] Order child post by order in parent back end

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

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 12 replies, has 2 voices.

Last updated by collinC-2 5 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#1362143

I am working on a real estate site that consists of a Property parent and Broker children. The order that the brokers are displayed on the Properties page will change depending on the property. For example, sometimes Mark is the lead broker on a property and displayed before Luke. Other times Luke the lead on a property and is displayed before Mark. This means I can't put the display order in the broker entry.

I would like to display them based on how they are listed in the Add a Broker section in the Dashboard back end of the Property entry. Is there a way to sort the results by the Property -> Broker relationship ID? I don't see that as one of the options in the order dropdown.

Are there any suggestions on how to achieve this? Please let me know if I can provide more information on my issue. Thank you.

#1362399

Hi Collin,

Thank you for contacting us and I'd be happy to assist.

Assuming that the "Property" and "Broker" post types are connected through a many-to-many relationship with a "Property Broker Intermediary Posts" set to be visible.

In this setup, you can create a view that shows "Property Broker Intermediary Posts" on a single "Property" page, to display the connected "Broker" posts, instead of directly selecting the "Broker" posts:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-information-from-intermediary-post-types

This will allow you to set the order of the view based on the post ID, which will effectively reflect the order in which a specific "Broker" was connected to a specific "Property".

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1362747

I think I see where you're going with this. There is a many-to-many relationship between the properties and brokers. When I go to that entry under Toolset > Relationships, i see at the bottom "Intermediary post type: No post type exists yet". The intermediate post type is not listed under Toolset > Post Types either. I did find this thread that that has instructions on how to make the intermediary relationships appear: https://toolset.com/forums/topic/sorting-posts-by-intermediary-field/. However, I don't see the Options panel that it refers to. Can you give me more detail where to find those settings?

#1363101

If an intermediary post's option is not checked at the time of the post-relationship creation, the "Use existing post type" button can be used to attach one later.
( it's available right next to the message "No post type exists yet" that you saw, in the relationship edit screen ).

You'll first create a new custom post type for this purpose and the default format used for the automatically generated intermediary post type is:

Post Type Title: {plural name of the parent post type} {plural name of the child post type} Intermediary Posts
e.g. Properties Brokers Intermediary Posts

Post Type Slug: {slug of the parent post type}-{slug of the child post type}
e.g. property-broker

Once a new custom post type has been created, it should show in the list, when you'll click the "Use existing post type" button.

Important note: After you'll have the intermediary post type in place for this relationship, a new post in it will be created automatically, whenever a new relationship will be created between a property and a broker. However, it will not include posts for the already joined properties and brokers.

As the original plan was to use a view that shows posts from this intermediary post type, you'll need to delete the already formed relationships and connect them again.
( so that an intermediary post exists for all the connections )

Please let me know how it goes and if any point is not clear.

#1363673
Image 015.png

I'm sorry but I don't see a button next to "No post type exists yet". Is there another setting I need to select first? Do I have my relationship set up incorrectly?

#1363977

Have you looked for this button after creating a new custom post type?
( ref: https://toolset.com/documentation/user-guides/getting-starting-with-types/#create-custom-post-types-from-the-toolset-dashboard )

If not, please register a new custom post type first and then see if the "Use existing post type" button becomes available.

In case it still doesn't show, a clone/snapshot of your website would help, in troubleshooting this relationship, on my own server.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

Your next reply will be private.

#1365601

I clicked the edit settings checkbox from the screenshot above and was able to create the intermediate post type. I updated the view to use information from the new type. In the view, I'm referring to property information like the broker name and featured image using the @property-broker notation like this:

[wpv-post-title item="@property-broker.child"]

However, I think that I might have skipped a step and I'm getting an error. Here's what shows up in the error log:

PHP Fatal error: Uncaught Error: Call to a member function get_type() on null in /mysite/wp-content/plugins/wp-views/application/controllers/filters/post/relationship/query.php:772\nStack trace:\n#0 /mysite/wp-content/plugins/wp-views/application/controllers/filters/post/relationship/query.php(144): WPV_Filter_Post_Relationship_Query->get_settings_post_in_with_m2m(Array, Array, Array)\n#1 /mysite/wp-content/plugins/wp-views/application/controllers/filters/post/relationship/query.php(64): WPV_Filter_Post_Relationship_Query->get_settings(Array, '3290')\n#2 [internal function]: WPV_Filter_Post_Relationship_Query->filter_query(Array, Array, '3290')\n#3 /mysite/wp-includes/class-wp-hook.php(286): call_user_func_array(Array, Array)\n#4 /mysite/wp-includes/plugin.php(208): WP_Hook->apply_filters(Array, Array)\n#5 /mysite/wp-content/plugins/wp-views/embedded/inc/wpv-filter-query.php(788): appl in /mysite/wp-content/plugins/wp-views/application/controllers/filters/post/relationship/query.php on line 772, referer: hidden link

If this error message isn't helpful in understanding what I did wrong, I'll get you access to the site so you can take a look directly. Thanks!

#1365967

Thank you for sharing the update, but unfortunately, the error message alone is not very conclusive.

The entire website will need to be troubleshooted on a different server as a whole, which is why a clone/snapshot will be needed in this case.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )

I'm setting your next reply as private again, so that you can share the files, securely.

#1366285

Thank you for sharing the details about the staging website, but the user doesn't seem to have the administrator privileges.

Please make sure that this user has the "administrator" role.

#1366309

Sorry! My mistake! You're an admin now. Please let me know if you need anything else.

#1366403

I can now access the back-end as the admin, thank you.

I'll be performing some troubleshooting steps and will share my findings, as soon as this testing completes.

Thank you for your patience.

#1367501

Thank you for waiting, while I performed some tests on your website's clone.

During troubleshooting, I noticed that while the new "Broker Orders" post type was successfully set as the "Properties Brokers" relationship's intermediary post type, no posts actually existed in that new post type.

This means that all or any relationships that were formed between the Properties and the Brokers, they were formed before the selection of this intermediary post type.
( a note about such a situation was included in my earlier message: https://toolset.com/forums/topic/order-child-post-by-order-in-parent-back-end/#post-1363101 )

To fix this, you can go to the edit screen of each property post ( e.g. hidden link ) and disconnect any existing broker post.

Once disconnected, you can connect the same broker posts again and this error will be fixed.
( you can then repeat the same for all the properties )

I hope this helps and please let me know how it goes.

regards,
Waqar

#1369159

That makes sense. I'll update my broker entries and the should resolve my issue. Thank you!