Title: Need help with a code
Last modified: June 11, 2020

---

# Need help with a code

 *  [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/)
 * Can anyone help with a custom hook/code to auto change the post in a category
   to another category every day at exactly 12:00AM.
 * I have three categories ( general, special, free )… I have contents with this
   categories; general & free. So I want any post in the FREE category to change
   automatically to SPECIAL 12:00AM Daily. So I will have the post in General + 
   SPECIAL category.
    -  This topic was modified 6 years ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Everything else WordPress
      topic

Viewing 15 replies - 16 through 30 (of 44 total)

[←](https://wordpress.org/support/topic/need-help-with-a-code/?output_format=md)
[1](https://wordpress.org/support/topic/need-help-with-a-code/?output_format=md)
2 [3](https://wordpress.org/support/topic/need-help-with-a-code/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/need-help-with-a-code/page/3/?output_format=md)

 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979380)
 * Thanks
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979383)
 * So, that means I can create the file anywhere?… Cos I don’t have a child theme
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979387)
 * You can place it anywhere really, as long at your php file has permissions set
   to 755, and you can access the wp-load.php file which is referenced in the script.
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979389)
 * Thanks so so much. I will update you
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979410)
 * [@corrinarusso](https://wordpress.org/support/users/corrinarusso/) Hi, I got 
   this in my mail;
 * X-Powered-By: PHP/7.4.6
    Set-Cookie: PHPSESSID=b1c8eeb08dac888059dec24224ce4d14;
   path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache,
   must-revalidate Pragma: no-cache X-LiteSpeed-Cache-Control: no-cache Content-
   type: text/html; charset=UTF-8
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979416)
 * What does it mean… I set the Cron job to run every 5mins just to be sure, and
   I got that mail after 5mins, the post were not moved either
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979417)
 * That’s not from my script, that’s from LightSpeed :
 * X-**LiteSpeed**-Cache-Control: no-cache
 * You should really turn your cache off while testing.
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979418)
 * Oh.. Okay
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979421)
 * I have deactivated the LiteSpeed Cache plugin, will wait for the next 5mins
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979434)
 * [@corrinarusso](https://wordpress.org/support/users/corrinarusso/) Here is what
   I got;
 * X-Powered-By: PHP/7.4.6
    Set-Cookie: PHPSESSID=bc5f8ed5bbfbe6147eadcc423a737f7e;
   path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache,
   must-revalidate Pragma: no-cache Content-type: text/html; charset=UTF-8
 * No post was moved too
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979446)
 * Can you post the content of the script file back into here pls?
    Also – again
   this is coming from your nocache header : [https://www.php.net/manual/en/function.session-cache-limiter.php](https://www.php.net/manual/en/function.session-cache-limiter.php)
   The expiry date is listed as : Expires: Thu, **19 Nov 1981** 08:52:00 GMT which
   is a nod to a php developer.
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979448)
 * You’ll need to post your code, as well as a screenshot of the cron, as well as
   that you changed the php file to have 755 permissions.
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979452)
 * I saw this in the error_log file;
 * Connection refused.
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979453)
 * Okay
 *  Thread Starter [Mikel](https://wordpress.org/support/users/ogmic/)
 * (@ogmic)
 * [6 years ago](https://wordpress.org/support/topic/need-help-with-a-code/page/2/#post-12979459)
 * Here is my code
 *     ```
       <?php
       // change the path to your wp-load.php file 
       require_once('/home/surepayf/public_html/wp-load.php'); 
       //$output = shell_exec('wp post list --category_name="FREE CONTENT" --format=ids 2>1&');
       //echo $output."\n";
       global $wpdb;
       $oldCatSlug = 'free-content';
       $newCatSlug = 248; // 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 CONTENT',
               )
           );
           if ( $posts ) {
               foreach ( $posts as $post ) {
                   // update categories the match FREE
                   // see https://codex.wordpress.org/Function_Reference/wp_set_post_categories
                   wp_set_post_categories( $post->ID, $newCatSlug, false ); // set this to true if you want this category appended
               }
           }
       }
       ?>
       ```
   

Viewing 15 replies - 16 through 30 (of 44 total)

[←](https://wordpress.org/support/topic/need-help-with-a-code/?output_format=md)
[1](https://wordpress.org/support/topic/need-help-with-a-code/?output_format=md)
2 [3](https://wordpress.org/support/topic/need-help-with-a-code/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/need-help-with-a-code/page/3/?output_format=md)

The topic ‘Need help with a code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 44 replies
 * 2 participants
 * Last reply from: [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/need-help-with-a-code/page/3/#post-13042864)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
