Sorry for so many questions in recent days. I want to choose the best way to create my website and i promise i will let you rest later 🙂
So is it possible to auto change taxonomy after specified time ?
I am creating an advertising portal where adding ads is free. Later, the user will be able to buy an advertisement promotion for a specified period of time (e.g. 30 days). I would like the advertisement to be transferred to the Taxonomy "Type of advertisement> Promoted" after the purchase and disappear from it after specified time.
Hi,
Thank you for contacting us and I'd be happy to assist.
To achieve this, you can use the automatic post expiration feature, as explained here:
https://toolset.com/course-lesson/setting-up-automatic-post-expiration/
You can set the promoted posts to expire in a set period (for example 30 days), but let them keep the original status after expiration.
Then using a custom function attached to the "cred_post_expiration_custom_actions" hook, you can remove that particular taxonomy term from the post, when it expires:
( https://toolset.com/documentation/programmer-reference/cred-api/#cred_post_expiration_custom_actions )
Example:
add_filter('cred_post_expiration_custom_actions', 'my_custom_actions', 10, 3);
function my_custom_actions($custom_actions, $post_id, $form_data) {
wp_remove_object_terms( $post_id, 'promoted', 'type-of-advertisement' );
return $custom_actions;
}
Note: you'll replace "promoted" and "type-of-advertisement" with the actual slug of the term "Promoted" and the taxonomy "Type of advertisement", respectively.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
regards,
Waqar