HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/linde-ai/wp-content/themes/linde/pages/articles.php
<?php
/*
 * Template Name: Articles
 */

$context = Timber::context();

global $paged;
if (!isset($paged) || !$paged){
    $paged = 1;
}

/*
 * Query arguments to fetch posts while filtering based on the custom ACF field 'post_visibility'.
 *
 * Filtering logic:
 * 1. Posts where 'post_visibility' **does not exist** (i.e., no visibility option selected) are included.
 *    - This ensures that posts without a manually set visibility option are shown.
 *    - The default option when 'post_visibility' is not explicitly selected is "website"
 * 2. Posts where 'post_visibility' is explicitly set to 'lva-platform' are excluded.
 * 3. Posts with any other value ("website" or "everywhere") are included.
 *
 * The 'relation' => 'OR' ensures that either of these conditions can be true:
 * - If the field does not exist → Show the post.
 * - If the field exists and IS NOT set to 'lva-platform' → Show the post.
 * - If the field exists and is set to 'lva-platform' → Exclude the post.
 */
$args = array(
    'numberposts' => 6,
    'paged' => $paged,
    'orderby' => 'date',
    'order'   => 'DESC',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'post_visibility',
            'compare' => 'NOT EXISTS' 
        ),
        array(
            'key' => 'post_visibility',
            'value' => 'lva-platform',
            'compare' => '!='
        )
    )
);

$news = new Timber\PostQuery($args);

$context['posts'] = $news;
$context['pagination'] = $context['posts'];

Timber::render( array( 'pages/articles.twig', 'page.twig' ), $context );