Files
agroexpert/partials/most-read-posts.php
argoexpert press 51d7df598b delete adv
2024-05-06 12:02:48 +03:00

33 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
global $wpdb; // Глобальная переменная для работы с базой данных
// Запрос для получения ID топ-3 просматриваемых постов
$query = $wpdb->prepare("
SELECT 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>';
}
?>