0

I have around 200 posts. I want to make all posts non-sticky except 4 posts. I know the id of those 4 posts. How can I do it? Using plugin or sql query?

3

You can use a simple script which you run once and remove. The idea is to replace the sticky post array with an array of the 4 desired ID's

PHP 5.4+ version - short array syntax

add_action( 'init', function ()
{
    // Define our new array
    $stickies = [1,2,3,4]; // Change to match your own ID's

    // Update the sticky posts option
    update_option( 
        'sticky_posts', // Option name 
        $stickies // New value 
    );
}, PHP_INT_MAX );  

Pre PHP5.4 version

add_action( 'init', function ()
{
    // Define our new array
    $stickies = array( 1,2,3,4 ); // Change to match your own ID's

    // Update the sticky posts option
    update_option( 
        'sticky_posts', // Option name 
        $stickies // New value 
    );
}, PHP_INT_MAX );  
  • 1
    My pleasure, glad it worked. Just one note on your edit, the array syntax I used is perfectly valid, BUT it does not work on PHP versions older than PHP 5.4. If you received an error regarding the array syntax, you are on a dinosaur version of PHP. At this stage, you should not be using any version below PHP 5.6 as the all previous versions are EOL'ed (PHP 5.5 will EOL in July), using this versions will lead to security issues ;-) – Pieter Goosen Feb 12 '16 at 8:58
  • Thank you once again for this information. I will update it. :) – vedu Feb 12 '16 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.