Skip Navigation

[Résolu] Display Relationship post with Gridbuilder WP

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

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 7 réponses, a 2 voix.

Dernière mise à jour par Nigel Il y a 5 années et 5 mois.

Assisté par: Nigel.

Auteur
Publications
#1251679

Hi since one year right now I used The Grid plugin from Themeone and I used the methode previously provided to me here: https://toolset.com/fr/forums/topic/display-view-content-with-the-grid-plugin-part-2/ to display my post into a grid.

But due to the lake of update and the oldest technology used by the plugin I decided to use a fresh new plugin GridbuilderWP lien caché from the same developper Themeone. Its praticaly the same plugin, but more powerfull and much faster than the older.

But I need to use Gridbuilder to display related post like I do before with The Grid Plugin. I used this code to do this :

[php]<?php
/**
* Permet à The Grid d'afficher correctement les articles en relation (Relationship) avec toolset. https://toolset.com/forums/topic/display-view-content-with-the-grid-plugin/ */
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

function my_query_args($query_args, $grid_name) {

if ($grid_name == 'Master Archive Grid') {

global $post;
error_log('$post: ' . print_r($post, true));

$related_posts = toolset_get_related_posts( $post->ID, 'branch-post', array( 'query_by_role' => 'parent', 'limit' => 999, 'return' => 'post_id', 'role_name_to_return' => 'other' ) );
error_log('related_posts: ' . print_r($related_posts, true));

$query_args['post__in'] = $related_posts;
}

return $query_args;

}
add_filter('tg_wp_query_args', 'my_query_args', 10, 2);[php]

I think I can use the same code but tweaked for Gridbuilder to do same thing, here documentation form Gridbuilder lien caché

I dont have technical knowledge so I dont know what to do, maybe changing Grid Name for Grid ID, because Gridbuilder use Grid ID to call there grid instead of Grid name.

#1251771

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi Marc

I helped you get this working before with the previous grid plugin.

I must say that just linking to another product's documentation and asking us to work out how to integrate with it is outside of our support policies.

However, it's not too busy here at the moment so let me take a look. It would probably help if I could see the plugin in action with its settings pages etc. Could I get access to your site?

I'll mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.

Can you also confirm where you are trying to insert this grid and what it should display?

#1251973

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

I've been exploring your site but I need some more direction about what you are trying to achieve.

You shared a link to lien caché

That is a single "Interest" post, which is displayed using an Elementor template, which contains the shortcode to insert the grid with id="1".

Can you confirm, what you want to do is change the query for the grid so that it displays posts related to the jeux-video post currently being displayed, is that right?

#1251991

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

(A quick follow-up to say that the API for the new plugin appears quite different than the old API and I'm not sure it is possible to filter posts in the same way. I need to set up a local test site to do some testing and will let you know when I've done that, in the morning.)

#1252005

Ok thank you for your hard work. And yes this is right I want the grid on the lien caché to display only post related to jeux-video like you said.

#1252799

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

I posted an update but it seems to have been lost, let me repeat, the issue was that the new plugin has changed the name of the filter which you use to modify the query arguments. I deactivated your existing custom code snippet and added a new one with the updated filter name and tested it and it appears to be working.

For reference, here's the code:

function my_query_args($query_args, $id) {
   
   if ($id === 1) {
 
       global $post;
 
       $related_posts = toolset_get_related_posts( $post->ID, 'go', array( 'query_by_role' => 'parent', 'limit' => 999, 'return' => 'post_id', 'role_name_to_return' => 'other' ) );
 
       $query_args['post__in'] = $related_posts;
   }
      
   return $query_args;
      
}
add_filter('wp_grid_builder/grid/query_args', 'my_query_args', 10, 2);
#1252807

Yes ! Thank everything seems to work fine. Best support ever Thank you !

#1252823

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Great, let's close here then.