Without examining it too closely you seem to be getting all of the garde posts and looping through them and testing for the date, and if any of them satisfy the date test, the last one of those that does will return the groupe-de-garde taxonomy terms for that post.
Debugging custom code is outside of our support policy, which is to say, I will look at this, but the queue is very busy today and it will be later when I can come back to it.
In the meantime, I don't see any reason to use the WordPress loop inside your shortcode, and I would switch to using a standard PHP foreach loop to iterate over the posts found by your query.
And then I would add some debugging info at key points in your code to verify that what happens at each step is what is expected.
So add lines like this...
error_log(print_r($posts, true));
...after your query then inspect your debug log to confirm that the expected posts are retrieved etc.
If you do that and there is a particular step that fails which you don't understand, please let me know the details.
Hello and thank you very much,
In deed with this new error code I get the right post (8642), but the term is "Array" instead of being the term ID or the term name. I tried to implode but it gets me a "impossible to convert to string" fatal error :
[18-Dec-2017 16:47:04 UTC] the terms of post ID 8642 are Array
(
[0] => WP_Term Object
(
[term_id] => 4
[name] => 2
[slug] => 2
[term_group] => 0
[term_taxonomy_id] => 4
[taxonomy] => groupe-de-garde
[description] =>
[parent] => 0
[count] => 26
[filter] => raw
)
)
What I need to output with the shortcode is the name of the term.
If you want it to return the name of a single term then you should be using wp_get_post_terms.
You need to specify that you want it to return the name field. It will return an array with all of the names of the assigned terms for the specified taxonomy.
If there will only be one term assigned then it is trivial to get that single name to return.
Not quite sure I understood but it works great. I'll go ahead and try to build the complete function on this base.
Thank you very much for your help ; it's been most usefull.