• 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 4 years, 9 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 15 replies - 16 through 30 (of 44 total)
  • Thread Starter Mikel

    (@ogmic)

    Thanks

    Thread Starter Mikel

    (@ogmic)

    So, that means I can create the file anywhere?… Cos I don’t have a child theme

    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

    (@ogmic)

    Thanks so so much. I will update you

    Thread Starter Mikel

    (@ogmic)

    @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

    (@ogmic)

    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

    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

    (@ogmic)

    Oh.. Okay

    Thread Starter Mikel

    (@ogmic)

    I have deactivated the LiteSpeed Cache plugin, will wait for the next 5mins

    Thread Starter Mikel

    (@ogmic)

    @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

    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
    The expiry date is listed as :
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    which is a nod to a php developer.

    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

    (@ogmic)

    I saw this in the error_log file;

    Connection refused.

    Thread Starter Mikel

    (@ogmic)

    Okay

    Thread Starter Mikel

    (@ogmic)

    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.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 this category appended
            }
        }
    }
    ?>
Viewing 15 replies - 16 through 30 (of 44 total)
  • The topic ‘Need help with a code’ is closed to new replies.