Site logo

Archived topic

Change custom taxonomy after certain time - CPT template

3 replies · Started by Prabakaran on October 10, 2021

Viewing posts 1–4 of 4

Hello,

I wish to change the custom taxonomy for the custom post type after a certain time similar to post expiration.
Custom taxonomy: current-status
term-id: 368
post-type: job

I have created the function wp_set_post_categories and wish to include it in the post-job template in the child theme after 'generate_do_template_part( 'page' );'. Does this create any issues?
`$nvs_taxonomy = 'custom-status';
//expiration time
$expirationtime = get_post_meta($post->ID, "expiration", false);
if( count( $expirationtime ) != '' ) {
if (is_array($expirationtime)) {
$expirestring = implode($expirationtime);
}
$secondsbetween = strtotime($expirestring)-time();
if ( $secondsbetween >= 0 ) {
echo 'This post will expire on ' .$expirestring.'';
the_content();
}
else {
function set_new_category( $post_id ) {
//Define new category by ID
$new_category = array( 368 );
$old_term = wp_get_post_terms( $post_id, $nvs_taxonomy );

if( is_array( $old_term ) && ! empty( $old_term ) ) {
if ( in_array( 'custom-status', $old_term ) {
wp_set_post_categories( $post_id, $new_category, $append = true );
}
}

}
}
}`

If this is not a place to ask this query, then, please accept my apologies and sorry for the inconvenience.

Hi there,

This isn't a theme question. Questions like this are best asked on https://wordpress.stackexchange.com/.

But to add to this:

I don't know what expiration's field format but if possible, I'd set it to a time format and compare its value to date() or time().

I will then do a diff() between expiration and current date like in this example - https://generatepress.com/forums/topic/acf-custom-fields-in-elements/#post-1934880

The code you've shared tries to do this in a way but I'm not exactly sure if that count is accurate. You may have to ask on stackexchange for that. :D

Thank you

No problem. :D

This archived topic is closed to new replies.