add correct meta calendar

This commit is contained in:
2021-11-01 02:22:21 +03:00
parent f97013cfaf
commit d9da333806
7 changed files with 140 additions and 56 deletions

View File

@@ -1,43 +1,65 @@
<?php
setlocale(LC_ALL, 'ru_RU');
date_default_timezone_set('Europe/Moscow');
function calend_block($month, $year, $script=false){
$args = array(
$find_sql = "
SELECT `post_id`
FROM `wp_postmeta`
WHERE `meta_key` = 'startevent' AND `meta_value` BETWEEN '$year-$month-01T00:00:00' AND '$year-$month-31T23:59:59'
";
$items = db_get($find_sql);
$ins = str_to_in($items);
if ($ins !== '') {
$posts = db_get("
SELECT ID, post_date, post_title FROM `wp_posts` WHERE ID IN ($ins)
");
}
/** $args = array(
'numberposts' => -1,
'category' => 61, // 61 - мероприятия
'orderby' => 'date',
'order' => 'ASC',
'date_query' => array(
'meta_query' => array(
array(
'after' => array( // после этой даты
'year' => $year,
'month' => $month,
'day' => 1,
),
'before' => array( // до этой даты
'year' => $year,
'month' => $month,
'day' => 31,
),
// 'inclusive'=> true
)
),
'key' => 'startevent',
'value' => array( "$year-$month-01T00:00:00", "$year-$month-31T23:59:59" ),
'compare' => 'BETWEEN',
'type' => 'DATE'
),
),
'post_type' => 'post',
'post_status' => 'publish, future',
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
);*/
$args = array(
'numberposts' => -1,
'post__in' => $ins
);
$posts = get_posts($args);
//$posts = get_posts($args);
$events = [];
foreach ($posts as $post){
$key = date('d.m.Y', strtotime($post->post_date));
$events[$key]['text'] = $post->post_title;
$events[$key]['link'] = get_permalink($post->ID);
if (is_array($posts)){
foreach ($posts as $post){
$eventdate = get_post_meta($post['ID'], 'startevent', true);
$key = date('d.m.Y', strtotime($eventdate));
$events[$key]['text'] = $post['post_title'];
$events[$key]['link'] = get_permalink($post['ID']);
}
}?>
<div id="event-calendar">