날짜 종료일 이후 카테고리 변경

코스모스팜 커뮤니티에서 검색해서 날짜입력필드에 시작일 종료일 까지 나타나는건 성공했습니다.

여기서 종료날짜가 지나면 카테고리가 변경되게 하고싶습니다.

/*kboard 시작,종료 날짜*/
add_filter('kboard_skin_fields', 'my_kboard_skin_fields', 10, 2);
function my_kboard_skin_fields($fields, $board){
	if($board->id == '1'){ // 실제 적용될 게시판 ID 값으로 변경해주세요.
		
		if(!isset($fields['date'])){
			$fields['date'] = array(
				'field_type' => 'date',
				'field_label' => '시작종료날',
				'class' => 'kboard-attr-text',
				'hidden' => '',
				'meta_key' => '',
				'field_name' => '',
				'permission' => '',
				'roles' => '',
				'default_value' => '',
				'placeholder' => '',
				'required' => '',
				'show_document' => '',
				'description' => '',
				'close_button' => 'yes'
			);
		}
	}
	
	return $fields;
}

add_filter('kboard_get_template_field_html', 'my_kboard_get_template_field_html', 10, 4);
function my_kboard_get_template_field_html($field_html, $field, $content, $board){
	
	if($field['field_type'] == 'date'){
		wp_enqueue_script('jquery-ui-datepicker');
		wp_enqueue_script('jquery-timepicker', KBOARD_URL_PATH . '/template/js/jquery.timepicker.js', array(), KBOARD_VERSION);
		wp_enqueue_style('jquery-flick-style', KBOARD_URL_PATH.'/template/css/jquery-ui.css', array(), '1.12.1');
		wp_enqueue_style('jquery-timepicker', KBOARD_URL_PATH.'/template/css/jquery.timepicker.css', array(), KBOARD_VERSION);
		
		ob_start();
		?>
		<div class="kboard-attr-row">
			<label class="attr-name" for="kboard_option_start_date"><?php echo __('시작일', 'kboard-cross-calendar')?><span class="attr-required-text">*</span></label>
			<div class="attr-value">
				<div class="calendar-event-start-date-set">
					<input type="text" class="datepicker" id="kboard_option_date" name="kboard_option_date" value="<?php echo $content->option->date?>" title="시작날짜" placeholder="시작날짜" readonly>
				</div>
			</div>
			
			<label class="attr-name" for="kboard_option_end_date"><?php echo __('종료일', 'kboard-cross-calendar')?><span class="attr-required-text">*</span></label>
			<div class="attr-value">
				<div class="calendar-event-start-date-set">
					<input type="text" class="datepicker" id="kboard_option_date2" name="kboard_option_date2" value="<?php echo $content->option->date2?>" title="종료날짜" placeholder="종료날짜" readonly>
				</div>
			</div>
		</div>
		<script>
		jQuery(document).ready(function(){
			jQuery('.datepicker').datepicker({
				closeText : '닫기',
				prevText : '이전달',
				nextText : '다음달',
				currentText : '오늘',
				monthNames : [ '1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월' ],
				monthNamesShort : [ '1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월' ],
				dayNames : [ '일', '월', '화', '수', '목', '금', '토' ],
				dayNamesShort : [ '일', '월', '화', '수', '목', '금', '토' ],
				dayNamesMin : [ '일', '월', '화', '수', '목', '금', '토' ],
				weekHeader : 'Wk',
				dateFormat : 'yy-mm-dd',
				firstDay : 0,
				isRTL : false,
				duration : 0,
				showAnim : 'show',
				showMonthAfterYear : true,
				yearSuffix : '년'
			});

		});
		</script>
		<?php
		$field_html = ob_get_clean();
	}
	
	return $field_html;
}
/*kboard_document_add_option_value_field_html 필터 */
add_filter('kboard_document_add_option_value_field_html', 'my_kboard_document_add_option_value_field_html', 10, 4);
function my_kboard_document_add_option_value_field_html($html, $field, $content, $board){
	if($board->id == '1'){ // 실제 적용될 게시판 ID 값으로 변경해주세요.
		$meta_key = (isset($field['meta_key'])&&$field['meta_key']) ? $field['meta_key'] : '';
		if($meta_key == 'date'){
			$html = '<div class="kboard-document-add-option-value meta-key-' . esc_attr($meta_key) . '"><span class="option-name">' . $field['field_name'] . '</span> : ';
			$html .= "<span class=\"option-name\">시작일</span> : {$content->option->date} <span class=\"option-name\">~ 종료일</span> : {$content->option->date2}</div><hr>";
		}
	}
	return $html;
}

또 어떤액션를 사용해야 하는걸가요?

/*종료일맞춰서 category1 자동 변환*/
add_filter('kboard_content', 'kboard_content_20241018', 10, 4);
function kboard_content_20241018($content, $content_uid, $board_id){
	if($board_id == '1'){ // 실제 게시판 id로 적용해주세요.
		$current_date = date('Y-m-d', current_time('timestamp'));
		$end_date = date('Y-m-d', $content->option->date2);
		
		if($current_date >= $end_date){
			if($content->category1 == '모집중'){
			$content->category1 = '모집완료';
			$content->updateContent();
		}
		}
	}
	
	return $content;
}

 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기