Skip Navigation

[Resolved] question – Migrate Your Site to New Post Relationships with my custom PHP

This support ticket is created 5 years, 6 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.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 5 years, 6 months ago.


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?

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

What is the link to your site?
hidden 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,



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:

In specific to get the related posts you'd use (single post) (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"

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