Skip Navigation

[Resolved] Create second toolset relationships query not working

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by Minesh 9 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2698736

I'm trying to create a second webhook.

Recently you helped me to succesfully create the following webhook:

add_action( 'elementor/query/person-post-query', 'atc_custom_query_01', 10, 2 );
function atc_custom_query_01( $query, $widget ){
  
    global $post;
  
    $query->set('toolset_relationships', array(
        array(
            'role'  =>  'child',
            'related_to' => $post->ID,
            'relationship'  => 'person-post'
        )
    ) );    
}

Which works correctly here: hidden link

I've tried to create a second webhook (Based on the above):

add_action( 'elementor/query/person-agenda-item-query', 'atc_custom_query_02', 10, 2 );
function atc_custom_query_02( $query, $widget ){
  
    global $post;
  
    $query->set('toolset_relationships', array(
        array(
            'role'  =>  'child',
            'related_to' => $post->ID,
            'relationship'  => 'person-agenda-item'
        )
    ) );    
}

And its NOT working here: hidden link

I've set the query ID to: person-agenda-item-query

The above query is based on this support ticket: https://toolset.com/forums/topic/custom-query-filter-and-display-related-posts-in-elementor/#post-2355219

Can you help me work out where I'm going wrong with the new/second webhook?

#2698900

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - you have post type "Person" and "Agenda Item" and you created the post-relationship person-agenda-item between those post type.

Now - I see you have the following page where the solution you applied is not working.
- hidden link

That means you are on currently "Agenda Item" single post but parent is "Person". You are using:
'related_to' => $post->ID,
- But that is current post ID that means of current Agenda Item post.

You will have to get the parent post (Person) ID.

Assuming you have one-to-many post relationship between your post type "Person" and "Agenda Item", what if you try to use the following modified code:

add_action( 'elementor/query/person-agenda-item-query', 'atc_custom_query_02', 10, 2 );
function atc_custom_query_02( $query, $widget ){
   
    global $post;

    /// get parent post ID
    $parent_id = toolset_get_related_post( $post->ID,'person-agenda-item');
    $query->set('toolset_relationships', array(
        array(
            'role'  =>  'child',
            'related_to' => $parent_id ,
            'relationship'  => 'person-agenda-item'
        )
    ) );    
}

More info:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#2698904

Hi Minesh,

Thank you for your reply 🙂

I've used the code as suggested, but it is still not working.

The Relationship type in use is Many to Many - might this be why?

Thankyou!

#2698923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I need to review your relationship structure and data.

Can you please tell me on what page and within what section of that page you want to display what content and send me admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#2698961

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've moved the code you added to functions.php fiel to "Custom Code" section offered by Toolset and adjusted it as given under:
- hidden link

add_action( 'elementor/query/person-agenda-item-query', 'atc_custom_query_02', 10, 2 );
function atc_custom_query_02( $query, $widget ){
    
    global $post;
 
    /// get parent post ID
    //$parent_id = toolset_get_related_post( $post->ID,'person-agenda-item');
    $query->set('toolset_relationships', array(
        array(
            'role'  =>  'parent',
            'related_to' => $post->ID ,
            'relationship'  => 'person-agenda-item'
        )
    ) );    
}

Can you please confirm it works as expected now.
- hidden link

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset