diff --git a/page-for-advertisers.php b/page-for-advertisers.php index bf306ab..9890f07 100644 --- a/page-for-advertisers.php +++ b/page-for-advertisers.php @@ -39,7 +39,7 @@ $advertisers = new WP_Query([ - On top + On top
diff --git a/partials/most-read-posts.php b/partials/most-read-posts.php index ee93dea..1e8da49 100644 --- a/partials/most-read-posts.php +++ b/partials/most-read-posts.php @@ -13,6 +13,7 @@ if (!empty($child_categories)) { $excluded_category_ids_in = implode(',', array_map('intval', $excluded_category_ids)); +/** $query = $wpdb->prepare(" SELECT DISTINCT p.ID, p.post_title, p.post_content, m.meta_value AS position FROM $wpdb->posts p @@ -25,6 +26,9 @@ $query = $wpdb->prepare(" AND tt.term_id NOT IN ($excluded_category_ids_in) ORDER BY CAST(m.meta_value AS UNSIGNED) ASC "); +*/ + + /** $query = $wpdb->prepare(" @@ -37,22 +41,48 @@ $query = $wpdb->prepare(" ORDER BY CAST(m.meta_value AS UNSIGNED) ASC ");*/ +$excluded_category_id = 740; + +// Запрос для получения всех постов с непустым метаполем 'top_participation_position' +$query = " + SELECT DISTINCT p.ID, p.post_title, p.post_content, m.meta_value AS position + FROM $wpdb->posts p + INNER JOIN $wpdb->postmeta m ON p.ID = m.post_id + WHERE p.post_type = 'post' + AND m.meta_key = 'top_participation_position' + AND m.meta_value != '' + ORDER BY CAST(m.meta_value AS UNSIGNED) ASC +"; + $top_posts = $wpdb->get_results($query); -// Вывод результатов if (!empty($top_posts)) { + foreach ($top_posts as $post) { - $permalink = get_permalink($post->ID); - $title = get_the_title($post->ID); -?> - -Нет просмотренных постов.

'; -} -?> \ No newline at end of file + // Проверка наличия категории или подкатегории с ID 740 + $terms = wp_get_post_terms($post->ID, 'category'); + $exclude = false; + foreach ($terms as $term) { + if ($term->term_id == $excluded_category_id || $term->parent == $excluded_category_id) { + $exclude = true; + break; + } + } + + if (!$exclude) { + + $permalink = get_permalink($post->ID); + $title = get_the_title($post->ID);?> + + + +