Skip Navigation

[Résolu] bulk editing relationships in the new toolset 3 format

This support ticket is created Il y a 5 années et 10 mois. 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : 

This topic contains 16 réponses, has 2 voix.

Last updated by Beda Il y a 5 années et 10 mois.

Assisted by: Beda.

Auteur
Publications
#905472

i use in my site the "advanced bulk edit" plugin to bulk relation classes to professors (many to one relation) . This is an amazing way i found as there is no option to bulk relate post to posts. The way i did it is by bulk editing the custom field "_wpcf_belongs_parent_id" and inserting there the professor id. How should i do such action in the new relationship format? thanks

#905529

It's not anymore possible to do such manipulation of the Custom Fields as the new relationships are stored in Custom Database tables.

Old relationships, even if migrated, will proceed to work with that hidden custom field.
New relationships will use a new Database structure that won't store this info in the native Post Data or WordPress Custom Fields.

We created a new API for the new relationship structures:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

If your 3rd party App can read what those functions return, it may be possible to re-hook the features, but I fear that will not be possible without a lot of custom code.

What we can do is file a request to bulk assign posts in the backend.

#905553

what about the possibility of populating the wpcf_belongs_parent_id with the old procedure - and than re-migrate this posts to be "compiled" to the new relationship format? (as it is done with old posts relationsships)

#905557

You can run the migration just once.
Of course, you are free to run a code snippet that for example on save_post() creates a _wpcf_belongs_{parent-post-type-slug}_id field and populates it as you want, but that would probably be only useful if you require that field.

A general solution would be to allow bulk assignments natively in Toolset

#905558

Is there any date planning for such important feature to be added natively?

#905566

No, this is not yet in our schedules, but I will share it with the developers tomorrow.

#905585

ok - here is what i tried to do by now with (seems) success:

1- i down-graded version of types
2- i re-created parent-child relation
3- i bulk edited posts with the "advanced bulk edit" plugin changing the _wpcf_belongs_parent_id custom field
4- i re-upgraded toolset 3
5 - all the parents (asigned with he "advanced bulk edit" plugin changing the _wpcf_belongs_parent_id custom field) seems to be recognized in the new release....

As a temporary solution - is there any problem doing this?

#905616

Well, it creates a mess of data using old (_wpcf_belongs_parent_id) and new (custom tables) data.
As well, it's very time intensive.

But I understand that you want to bulk update those posts.

The only what I could think of is a Custom code solution with a Toolset Form.
That could make it possible to choose several posts on one select field and update the current post with the new connection.

#905689

"Well, it creates a mess of data using old (_wpcf_belongs_parent_id) and new (custom tables) data."
How is it possible that the toolset system refers to two parent formats?

"The only what I could think of is a Custom code solution with a Toolset Form.
That could make it possible to choose several posts on one select field and update the current post with the new connection."
is it possible to help me doing this?

#905701

bsd

How the new system points from one post to the other? isn't a custom field (hidden?) that points to the parent Id?

#906072

How is it possible that the toolset system refers to two parent formats?

Let me explain.

Until now, Toolset allows a unidirectional relationship, between 2 post types, where you could connect one of a type to many of a type.
This was easily possible by adding a hidden custom field referring to the parent (_wpcf_belongs_parent_id).

With the new releases, the relationships you can build are more complex, they can now have a many of a type to many of a typical connection, and storing this information the same way as before was not the correct solution.

Hence, these new relationships are stored in a new way.
The connection does not figure anymore as before in that hidden field but is stored with help of new Database tables.
We offer an API to access this data programmatically:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

But of course the entire Toolset is designed to work within itself with this (and the old) relationships, there is usually no need to use that API.

How the new system points from one post to the other? isn't a custom field (hidden?) that points to the parent Id?

No, as mentioned, this is not happening anymore.
You can see the API and how we get the data (or set it) here:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
It's not anymore referring to a Post Field.

I can help you to create a front-end management form, where we will try to allow selecting several posts of one kind, and connect them to a post of another kind.

This is natively not yet possible with Toolset Forms, what you can do natively is to connect one post of a kind to another a time, in a Relationship Form.
This is explained here:
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

I assume this will not be what you need, rest assured our Developers are thinking of ways to allow selecting several posts a time (this would solve your requirement, right?).

For now, I could think of a custom code solution together with native Toolset Features.

I need to know from you if these specifications would make sense:
- On the Front End you would be presented with a Multiselect, or Checkboxes field, populated with existing Posts of one kind, and next to it, a select or radio field to choose the post (single) to connect the chosen multiple posts.
- A submit button as used to from Forms
- On submit, all posts chosen in the first field of type A, are connected to the one post chosen in Field B.

I think this should not be too difficult to achieve.
We will need to create some code that runs the new API on submit.

Can you let me know if this sounds like what you need?
I also need to know what kind of relationship you use, whether a many to many or one to many relationships.
Please remember that this will work for new relationships only, not migrated ones.

I will then craft an idea and a code sample that could be adapted.
For advanced help on customizing the code however we cannot help here, but instead, offer contact to skilled private Developers:
https://toolset.com/contractors/

#906095

"- On the Front End you would be presented with a Multiselect, or Checkboxes field, populated with existing Posts of one kind, and next to it, a select or radio field to choose the post (single) to connect the chosen multiple posts.
- A submit button as used to from Forms
- On submit, all posts chosen in the first field of type A, are connected to the one post chosen in Field B."
SOUNDS GRATE!
right now i use only a one to many relationship
also i need the possibility to filter the posts presented with multiselect or checkboxes by text that appears in the title or description od the post (childs posts)

"Please remember that this will work for new relationships only, not migrated ones."
why is that? after migration the system build the new data tables doesn't it?

thanks a lot for helping!

i will explain also what i do in the site:
i import 2000 youtube videos in posts (with the yt title being wp post title and samething to description)
Than i want to connect each video according to the text to a specific Rabbi (professor) .
so i have a one(rabbi) to multiple (video classes posts) relationship

you can take a lokk of an example of a amzing perfomance of toolset in this link
hidden link
(no va tener problemas con el espanol 🙂 - mi mama es argentina:))

Gracias mas una vez!

#906153

OK, I will look into possible approaches.

Please understand that this will be a little under the normal priority, as I will need to first handle BUG reports and non-custom-code issues.

I will, however, have an idea and sample ready within a day or 2 max.

Thanks

#906185

bsd

sounds greate
gracias mas una vez

#907746

Please acknowledge that this features will be added to Toolset in Future and that it is subject to Custom Code which we support only limitedly.

I am giving here a simplified example, to use if you cannot wait for the features, which you need to adapt to your specific install.
Once the features are added to Toolset, these codes probably would need to be removed.
We assume no responsibility for problems arising with this code, although, there should not be any, I tested it carefully.
But, please acknowledge that this is a custom solution, and not an official solution (which will be included with new features eventually).

Enough of the warnings and disclaimers, here is how you can bulk-connect many posts of one kind, to one post of a kind, in the Front End.
This Example assumes a one-to-many relationship.
However, it should as well be adaptable to a many to many relations.
The main point, however, is, that in the Front End you will always connect ONE to MANY posts, never MANY to MANY as that is simply not possible to manage (which post is connected to which?)

Note that this could as well be done in a View Loop which displays several Toolset Relationship Forms, which with each you can create a new relation.
But, in this case, you will click as many times you want to connect.
That is not what we wanted, we want one form to submit, and with that, you connect 200 posts at once to one post of another type.

Steps:
- Create 2 Post Types
- Create a Relationship, one to many. Note, in my example, one is left, many is right.
- Create 1 Post in the single part of the relationship (left side)
- Create many Posts in the many part of the relation (right side)
- Create a View, and query the "many" part post type (right side)
- Create a valid JSON ouput of Post ID and Post Name in the View loop:

[wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found]

- refer to this post how to output that JSON as a raw value:
https://toolset.com/forums/topic/cruft-output-by-views/#post-610342
(you will add that function to your functions.php and adapt it)
- Create a Post Form, which edits the "single" part of the relationshiop (it edits post type of "left side")
- In that form add a generic Checkboxes Field and pass a Shortcode as the value (the shortcode is the view you just created)
==> Make sure to use single quotes for the view's shortcode!
- Check that your Form, if inserted to a "left side" post, is displaying the "right side" posts fine (as checkboxes to be chosen)
- Now, create a cred_save_data() hook that takes the Post ID edited, and the Post ID passed in the generic Field, then runs an update to the database using our API to connect the posts:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==10)
    {
        if (isset($_POST['parents_to_connect']))//this is our generic checkboxes field
        {
        	$post_ids_to_connect = $_POST['parents_to_connect'];

        	$relationship = 'left-side-post-right-side-post';//our relationship slug

        	foreach ($post_ids_to_connect as $post_id_to_connect) {

                        //For each post we want to connect, connect it to the currently edited post
        		toolset_connect_posts( $relationship, $post_id, $post_id_to_connect );
        	}
        	
        }
    }
}

Submit the form, and see that each Post you chose, is no bulk-connected to the one post we edited.

This is a simple approach to allow bulkl editing in the front end.

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