Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    The sticky status is maintained in the options table under the name ‘sticky_posts’. The value is an array of post IDs. Thus you would insert a post row as usual, note the ID, then add the ID to the ‘sticky_posts’ array (or create it if it does not exist).

    Thread Starter maxou64

    (@maxou64)

    Thank you bcworkz.
    Here is the content of my table “sticky_posts” :
    a:1:{i:0;i:13;}
    Anyone could help me to have the correct php-mysql syntax to transform this ?
    I would like to add the post id 14 as a “sticky post”
    Thanks a lot

    Moderator bcworkz

    (@bcworkz)

    You have a serialized array string there. This is how all arrays are stored in the DB. Use unserialize() on the string to make it into a PHP array. Add your new ID to the array, then serialize() it before updating the value in the options table.

    Thread Starter maxou64

    (@maxou64)

    Thanks,

    Here is my php code :

    while ($res3 = $req2->fetch()){
    $rArray[] = $res3->post_id;
    }
    $jSticky=serialize($rArray);
    print_r($jSticky);

    but it’s not work as it’s return this :
    a:3:{i:0;s:2:”55″;i:1;s:2:”84″;i:2;s:3:”127″;}

    but wordpress want this format instead :
    a:3:{i:0;i:55;i:1;i:84;i:2;i:127}

    Have you got an idea ? how to return the good format ?

    Thanks you so much

    Moderator bcworkz

    (@bcworkz)

    Hmm, that’s curious. $res3 seems to be storing IDs as strings, not integers. This should fix it:
    $rArray[] = (int)$res3->post_id;

    Thread Starter maxou64

    (@maxou64)

    thanks bcworkz ! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘mysql query to add stikcy post’ is closed to new replies.