Hi @ogmic
I would prefer that you were a lot stricter in your requirements. There is no data validation in this at all, and I don’t really know the scope of your entire site or your request. So to be clear, the only requirement being met here is to change all posts with Category FREE to category SPECIAL at midnight every day.
The code above does not run, it’s only pseudo code.
1. Create a file in your child theme directory called movecategory.php
Do you already have a child theme set up for your site ?
If you don’t have a child theme set up, then login to your control panel, or ftp and create a file called movecategory.php
Copy and paste in this code into your php file (I’ve tested it, it works, but it’s not optimized!) :
<?php
// change the path to your wp-load.php file
require_once('/home/full-path-to-your-root-wordpress/public_html/your-website.com/wp-load.php');
//$output = shell_exec('wp post list --category_name="FREE" --format=ids 2>1&');
//echo $output."\n";
global $wpdb;
$oldCatSlug = 'FREE';
$newCatSlug = 86; // you need to insert an integer here that matches your SPECIAL category
$category = get_category_by_slug( $oldCatSlug );
if ( $category ) {
$posts = get_posts( array(
'numberposts' => -1,
'category_name' => 'FREE',
)
);
if ( $posts ) {
foreach ( $posts as $post ) {
// update categories the match FREE
// see https://codex.www.ads-software.com/Function_Reference/wp_set_post_categories
wp_set_post_categories( $post->ID, $newCatSlug, false ); // set this to true if you want th
is category appended
}
}
}
?>
Save the file.
Login to your control panel, and set up a cron – this is how it is done in Siteground :
https://www.siteground.com/tutorials/cpanel/cron-jobs/#:~:
That’s it.
You may have to disable the WordPress cron, like this :
https://www.siteground.com/tutorials/wordpress/real-cron-job/
It’s very simple.
But if you are struggling with how to create files, and upload them, you may need to ask a developer who has access to your website to help out.