Skip Navigation

[Résolu] question – Migrate Your Site to New Post Relationships with my custom PHP

This support ticket is created Il y a 6 années et 3 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Beda Il y a 6 années et 3 mois.

Auteur
Publications
#1079827

Tell us what you are trying to do? updating site to the new toolset plugins and keep custom php function work correctly

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#public-functions-for-getting-related-posts

Is there a similar example that we can see?
i don't know

What is the link to your site?
lien caché

I'm trying to understand if the following custom code (example) required an adaptation to support the new types relationship

...
//Parent Post ID
	$edu_parnt_id = wpcf_pr_post_get_belongs( $post_ID, 'education-parent' );	
	// get all education child posts related to the parnet
        $edu_chld_posts = get_posts(array(
            'numberposts'   => -1,
            'post_type'     => 'education',
			'meta_query' => array(array('key' => '_wpcf_belongs_education-parent_id', 'value' => $edu_parnt_id))
            )
        );
...

please note that i don't use the WP_Query() in my code at all.

Please advise,
Thanks,

David

#1080210

Not if you do (on your website) use only relationships that are "old" (even if migrated).
If you plan to create new relationships you should update it.

Nowadays for the same as you do with your code you'd follow this:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

In specific to get the related posts you'd use
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post (single post)
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts (many)

For example, the same as you have here:

$edu_chld_posts = get_posts(array(
            'numberposts'   => -1,
            'post_type'     => 'education',
            'meta_query' => array(array('key' => '_wpcf_belongs_education-parent_id', 'value' => $edu_parnt_id))
            )
        );

Is now this:

$parent_id == '1';//Pass the ID of the post of which you want to get related posts (usually $post->ID if you are on a current parent post...)
$edu_chld_posts = toolset_get_related_posts(
    $parent_id, // get posts related to this one
    'relationship-slug-here', // relationship between the posts
    'parent', // get posts where $writer is the parent in given relationship
    99, 0, // pagination
    array(),/additional query
    'post_object'//what to return
    'child' //what relation side to return 
);

It seems that you use a Many To Many Relationship, and get the related of the current post, then it's child.
That is like getting the related post of the current post in a new Many To Many Relationship API, as above shown.
Just, you skip the middle post type and can get to it directly, by passing the "parent", and expecting the "Childs"