• Cześć, potrzebuję rozwikłać problem dot. archiwizacji postów.
    Czyli:
    Z Strony głównej do strony archiwum aby przenosiło posty starsze niż 3 miesiące

    Dodałem kod php do functions.php

    function assign_category_for_old_posts($post_id) {
        $three_months_ago = strtotime('-3 months');
    
        if (get_post_time('U', false, $post_id) < $three_months_ago) {
    
            $archive_category_id = 123; 
    
    
            $current_categories = wp_get_post_categories($post_id);
    
    
            if (!in_array($archive_category_id, $current_categories)) {
    
                wp_set_post_categories($post_id, array_merge($current_categories, array($archive_category_id)));
            }
        }
    }
    
    add_action('save_post', 'assign_category_for_old_posts');

    Ustawiłem aby wyświetlała dana strona tylko archiwum kategorie, lecz nic się nie dzieje..
    Ustawiłem również swój szablon z kodem php takim:

    <?php
    /*
    Template Name: Posty Starsze niż 3 miesiące
    */
    get_header();
    ?>
    
    <div id="primary" class="content-area">
        <main id="main" class="site-main">
            <?php
            $three_months_ago = date('Y-m-d', strtotime('-3 months'));
            $args = array(
                'post_type'      => 'post',
                'post_status'    => 'publish',
                'date_query'     => array(
                    'before' => $three_months_ago,
                ),
            );
    
            $query = new WP_Query($args);
    
            if ($query->have_posts()) :
                while ($query->have_posts()) :
                    $query->the_post();
       
                endwhile;
                wp_reset_postdata();
            else :
                echo 'Brak postów spełniających kryteria.';
            endif;
            ?>
        </main>
    </div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    I wyświetla on i tak wszystkie posty.


    Mógłby ktoś pomóc?
    Używam motywu PHLOX
    W Skrócie
    Chciałbym aby z strony głównej posty starsze niż 3 miesiące były przenoszone do strony archiwum.

    Pozdrawiam

  • Temat ‘Przenoszenie postów starszych’ jest zamknięty na nowe odpowiedzi.