Skip Navigation

[Gelöst] question – Migrate Your Site to New Post Relationships with my custom PHP

This support ticket is created vor 6 Jahre, 1 Monat. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Beda vor 6 Jahre, 1 Monat.

Author
Artikel
#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?
versteckter Link

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"

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.