This support ticket is created Il y a 6 années et 6 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.
This function will allow you to get all connected posts in a relationship.
Then, you can, for example, use the native PHP Function "count()" to count how many post ID's you received and return that in a ShortCode. lien caché
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
Hi there
I think your best option here is to write a PHP function that uses the new relationships API function toolset_get_related_posts to return the number of related posts.
You can then register that function to be used in conditional shortcodes at Toolset > Settings > Front-end Content.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
Is this a new M2M relationship rather than a migrated relationship?
The arguments for toolset_get_related_posts are:
[php]
1. post ID or post object from one end of the relationship
2. relationship slug (for new relationships) OR an array of the connected post types for old relationships,
3. role of 1 above in the relationship (e.g. we are starting from the parent)
4. limit
5. offset
6. args array (for meta queries)
7. return post_id's or post_object's
8. role of posts to be returned (e.g. if 3 is parent this would be child)
The remaining arguments are optional, but you need to supply all of the above.
Note that it is possible to return the post count in a variable you specify if you also supply the remaining arguments, so that you wouldn't have to use count().
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
The offset is typically used for pagination.
Together with limit you might say "show me 10 results starting from the 11th result" which would effectively be showing the second page of results where you have 10 results per page.
Regarding your second code sample, the final parameter should be a variable name, which will then contain the number of results.
So if you change the last argument to $found_rows, for example, then you should be able to return $found_rows rather than $autori.
I haven't tested it myself, you are passing the variable by reference, it may be that you have to declare the variable before using it as an argument in toolset_get_related_posts (e.g. set it to zero first).