Advance Custom Fieldのデイピッカーを使い、繰り返しで日付を選び、
カレンダーにリンクを表示させたいです。
カレンダーにはwp-includesのgeneral-template.phpのカレンダーになる部分からfunctions.phpにコピーし、カレンダーとカスタムフィールド(値が単)を表示することが出来たのですが、カスタムフィールドが繰り返しになるとmeta_keyの部分やmeta_valueの部分をどう書けばいいのかわからず困っております。
現状はカスタムフィールドは単の_custom_event_dateというkeyで設定しています。
そこを繰り返しのdate_repeatのdate(複数設定)に変更しても表示できるように変更したいです。。
// カレンダーの日付の部分 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(meta_value) FROM $wpdb->posts as p left outer join $wpdb->postmeta as pm on p.id = pm.post_id WHERE pm.meta_key = '_custom_event_date' AND pm.meta_value >= '{$thisyear}-{$thismonth}-01 00:00:00' AND post_type = 'event' AND post_status = 'publish' AND pm.meta_value <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { $daywithpost[] = $daywith[0]; } } else { $daywithpost = array(); } // See how much we should pad in the beginning $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins ); if ( 0 != $pad ) { $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr( $pad ) .'" class="pad"> </td>'; } $newrow = false; $daysinmonth = (int) date( 't', $unixmonth ); for ( $day = 1; $day <= $daysinmonth; ++$day ) { if ( isset($newrow) && $newrow ) { $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; } $newrow = false; if ( $day == gmdate( 'j', $ts ) && $thismonth == gmdate( 'm', $ts ) && $thisyear == gmdate( 'Y', $ts ) ) { $calendar_output .= '<td id="today">'; } else { $calendar_output .= '<td>'; } if ( in_array( $day, $daywithpost ) ) { // any posts today? $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); /* translators: Post calendar label. 1: Date */ $label = sprintf( __( 'Posts published on %s' ), $date_format ); $searchUrl = esc_url( home_url( '/' ))."event/?meta_key=_custom_event_date&meta_value=".$thisyear."-".$thismonth."-".str_pad($day, 2, 0, STR_PAD_LEFT); $calendar_output .= sprintf( '<a href="%s" aria-label="%s">%s</a>', $searchUrl, esc_attr( $label ), $day ); } else { $calendar_output .= $day; } $calendar_output .= '</td>'; コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。