Skip Navigation

[Résolu] Using [cred-post-expiration] With Posts With Relationships

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Using [cred-post-expiration] With Posts With Relationships

Solution:
You should add custom shortcode to get the parent post expiration.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/using-cred-post-expiration-with-posts-with-relationships/#post-923869

Relevant Documentation:

This support ticket is created Il y a 6 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
- 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)

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

Dernière mise à jour par julieP Il y a 6 années et 4 mois.

Assisté par: Minesh.

Auteur
Publications
#921155

I'd like to display the expiry date of the parent post in the body of the email that is triggered by the child post. I tried [cred-post-expiration item="@relationshipslug.parent" format="d/m/Y"] but it didn't work. How do I achieve this please?

#921738

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Please check the following Doc:
=> https://toolset.com/documentation/user-guides/automatic-post-expiration/#displaying-information-about-the-expiration-date-on-the-front-end

[cred-post-expiration id="15" format="m/d/Y"]

As you can see - the [cred-post-expiration] shortcode accepts the id attribute. What if you try to pass your parent post ID to id attribute.

#922340

That would be fine if the expiry date I wanted to display the expiry date belonging to a specific post but I'd like to display the expiry date of the 'parent' post and this will change depending on which 'child' post is involved.

(You've enabled the 'debug info box but debug info is irrelevant; this is a general enquiry and not site specific.)

#922390

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

I would like to know here - do you have parent post ID available as URL param?

What I try to suggest is - you should try to find a way to get the parent post ID and then assign it to the id attribute of [cred-post-expiration] shortcode.

If you do not know how to do this, please share problem URL and access details so that I will look in to it and guide you in right direction.

#923869

do you have parent post ID available as URL param
How would this be available in the body of an email notification and how would I use it?

I've created my own shortcode to return the parent post ID (where posta-postb is the relationship slug):-

add_shortcode( 'parent_post_id', 'parent_post_id_shortcode');
function parent_post_id_shortcode( $atts ) {
   global $post;
   
   //get the parent Post ID
   $parentpostid = toolset_get_related_post($post_id, 'posta-postb' );
   
   return $parentpostid;
}

and then used the cred expiration shortcode like this:-

[cred-post-expiration id="[parent_post_id]" format="d/m/Y"]

My shortcode returns the parent ID when used on its own but when used inside the cred shortcode, the output is "].

I don't know how else to return the parent ID and would appreciate your assistance. Thank you.

#923913

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

As I said before:

What I try to suggest is - you should try to find a way to get the parent post ID and then assign it to the id attribute of [cred-post-expiration] shortcode.

You did it using the shortcode and the way you did is also acceptable method as well.

#948360

Is there any reason why you haven't suggested I try using the pre-existing toolset shortcode [wpv-post-id]?

#948365

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Because - I dont know where the CRED form is added to parent post or any page or any other custom post type post. So post ID will be vary based on the situations I mention and that is why I suggested you to use shortcode so we will have accurate parent ID.

#952070

The parent post ID can be called within the [wpv-post-id] shortcode meaning it wouldn't matter where or how the child post is added to the parent. Writing a shortcode of my own is simply re-inventing the wheel. I'm surprised you're making this more difficult than it needs to be; this isn't your normal approach.