Question

I want to create custom archive template for below requirements,

I have set a configuration in admin panel settings, from which admin can set time periods for archive news.

When a new time period is applied from admin side, it should run on the news items in the CMS, and automatically add news items which are older than the time period (i.e : 30 days ) to the archived category. On the news listing page, only the news items which are not in the archived category should be displayed. When the "View archived news" button is clicked, there should be a new page displayed which has the same template as the news listing page, but which shows all news items in the archived news category.

For Example : if i have 10 posts with category "news", now if i set archive days= 10 from backend settings, then after 10 days all the posts which are older than the 10 days will automatically assign new category "category_archive".

Updated :

function custome_archive_news($posts_array){

    foreach($posts_array as $key => $postVal){

    $slug = $posts_array->post_name; 

        $today = date("r");
        $articledate = date('r',strtotime($postVal->post_date));

        $difference = round((strtotime($today) - strtotime($articledate))/(24*60*60),0);

                if ($difference >= 30) {

                  wp_set_post_terms( $postVal->ID,'archivecategory','category',false);

                }

        }

    }

Can anybody please help me for this.

Thanks, Chandresh

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top