File: /var/www/linde/wp-content/themes/linde/single.php
<?php
/**
* The Template for displaying all single posts
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/
$context = Timber::context();
$timber_post = Timber::get_post();
$context['post'] = $timber_post;
$context['articles_page_link'] = get_field('articles_page', 'options');
$current_post_id = $timber_post->ID;
$args_base = [
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => ['date' => 'DESC'], // Ensure sorting by date
'meta_query' => [
'relation' => 'OR', // Allow either condition
[ // don't include posts set to be visible only on the lva platform
'key' => 'post_visibility',
'value' => 'lva-platform',
'compare' => '!=',
],
[
'key' => 'post_visibility',
'compare' => 'NOT EXISTS', // Include posts without this field
]
],
'posts_per_page' => 1,
'fields' => 'ids', // Only get post IDs
];
$prev_args = array_merge($args_base, [
'date_query' => [
['before' => get_the_date('Y-m-d H:i:s', $current_post_id),
'inclusive' => false,
]
]
]);
$previous_post = get_posts($prev_args);
if (!empty($previous_post)) {
$context['previous_post'] = Timber::get_post($previous_post[0]);
}
$next_args = array_merge($args_base, [
'orderby' => ['date' => 'ASC'],
'date_query' => [
[
'inclusive' => false,
'after' => get_the_date('Y-m-d H:i:s', $current_post_id)]
]
]);
$next_post = get_posts($next_args);
if (!empty($next_post)) {
$context['next_post'] = Timber::get_post($next_post[0]);
}
Timber::render( array('single.twig' ), $context );