Skip Navigation

[Resolved] custom query filter and display related posts in elementor

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

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 7 replies, has 2 voices.

Last updated by nealM 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2352779

Tell us what you are trying to do? Display only related child posts in Elementor using posts widget set to show child posts type.

Is there any documentation that you are following? Support ticket here seems to be resolved but I can't replicate it on my test site : https://toolset.com/forums/topic/display-related-posts-from-toolset-via-elementor-custom-query-id/

Is there a similar example that we can see? No

What is the link to your site? hidden link

#2353437

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share more details about what post relationship you created with what post type and what Elementor template you are using and share 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 have set the next reply to private which means only you and I have access to it.

#2353571

Minesh
Supporter

Languages: English (English )

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

Can you please check now. I've adjusted the code you added to the code snippet as given under:

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

I can see the result set is restricted to the related posts now:
- hidden link

Can you please confirm it works as expected.

#2353615

It works, thanks! Looks like it works with the native/basic Elementor posts widget. Do you have an idea what I was doing wrong?

Also, any idea why this query filter does not work with third party post widgets like AE POST BLOCKS ADV?

#2353667

Minesh
Supporter

Languages: English (English )

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

There was a spaces available with the hook name:

add_action( 'elementor/query/ts_mod_elem_query  ', 'ts_mod_elem_query', 1, 0 );

Which I changed to:

add_action( 'elementor/query/ts_mod_elem_query', 'ts_mod_elem_query', 10, 2 );

Also, any idea why this query filter does not work with third party post widgets like AE POST BLOCKS ADV?
==>
This question you will have to ask to Elementor support as you are using the Elementor hook.

#2354783

My issue is resolved now. Thank you!

#2355203

This function works fine with regular post type relationships. But what about custom post type relationships?
It did not work when I modified the function for the custom post type relationship : 'numero-commentaire-de-lecture' where the relationship is between parent 'numero' and the children from CPT 'commentaire-lecture' (slug).
What am I doing wrong?

add_action( 'elementor/query/ts_mod_elem_query', 'ts_mod_elem_query', 10, 2 );
function ts_mod_elem_query( $query, $widget ){

global $post;
$query->set('toolset_relationships', array(
array(
'role' => 'child',
'related_to' => $post->ID,
'relationship' => 'numero-commentaire-de-lecture' <-modified here, but no result
)
) );
}

#2355219

Finally it is working. I didn't set the correct settings on the widget!
I was looking for a third party widget query, if anyone needs it, this one worked for me:

function ae_ts_mod_elem_query_function2( $query_args ){

global $post;
$query_args['toolset_relationships'] = array(
array(
'role' => 'child',
'related_to' => $post->ID,
'relationship' => 'numero-commentaire-de-lecture'
)
);
return $query_args;
}
add_action( 'ae_ts_mod_elem_query2', 'ae_ts_mod_elem_query_function2' );

My issue is resolved now.

Thank you!