correct agrotop rus

This commit is contained in:
argoexpert press
2024-05-27 16:26:16 +03:00
parent 2ecc4e4089
commit f871c62628
2 changed files with 46 additions and 16 deletions

View File

@@ -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);
?>
<div class="most-read__link">
<a href="<?php echo esc_url($permalink); ?>" class="most-read__link-inner text-13 link-icon-after">
<?php echo esc_html($title); ?>
</a>
</div>
<?php
}
} else {
echo '<p>Нет просмотренных постов.</p>';
}
?>
// Проверка наличия категории или подкатегории с 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);?>
<div class="most-read__link">
<a href="<?php echo esc_url($permalink); ?>" class="most-read__link-inner text-13 link-icon-after">
<?php echo esc_html($title); ?>
</a>
</div>
<?}
}
}?>