1

In MySQL (for wordpress) there is the following value in a post_metadata :

a:1:{i:0;a:2:{s:5:"title";s:7:"Payment";s:19:"percentage_complete";s:1:"5";}}

We do :

$value_percentage = array (
      0 => 
      array (
        'title' => 'Payment',
        'percentage_complete' => '15',
      ),
    );
$serializedData = serialize($value_percentage);
update_post_meta( $id, $field_percentage, $serializedData );

But in the DB there is :

s:78:"a:1:{i:0;a:2:{s:5:"title";s:7:"Payment";s:19:"percentage_complete";s:2:"15";}}";

How to avoid the s:78:" ?

We also tried the following :

$value_percentage['percentage_complete'] = '15';

but there is the s:78:" in the DB

1
  • 1
    try directly using the $value_percentage variable. update_post_meta( $id, $field_percentage, $value_percentage ); Commented Nov 22, 2015 at 2:55

1 Answer 1

1

You can use maybe serialize and maybe_unserialize function to store and pull data

maybe unserialize

$string = 'a:1:{i:0;a:2:{s:5:"title";s:7:"Payment";s:19:"percentage_complete";s:1:"5";}}';
echo '<pre>', print_r(maybe_unserialize($string), 1), '</pre>';

output is like this,

Array (
    [0] => Array (
            [title] => Payment
            [percentage_complete] => 5
        )

)

maybe serialize

$value_percentage = array (
      0 => 
      array (
        'title' => 'Payment',
        'percentage_complete' => '15',
      ),
);
echo '<pre>', print_r(maybe_serialize($value_percentage), 1), '</pre>';

output is

a:1:{i:0;a:2:{s:5:"title";s:7:"Payment";s:19:"percentage_complete";s:2:"15";}}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.