0

When I use the following code:

update_post_meta($new_post_id, '_test_metakey1', 'a:1:1;');
update_post_meta($new_post_id, '_test_metakey2', 'a:1;');

The database adds the keys as follows: enter image description here

Why does _test_metakey1 save as s:6:"a:1:1;"; rather than just a:1:1;

This is just test code, the actual code I am trying to run for creating custom quizzes in LearnDash, the real code is here below, but has the same issue:

update_post_meta($new_post_id, '_sfwd-quiz', 'a:77:{i:0;s:0:"";s:33:"sfwd-quiz_startOnlyRegisteredUser";b:0;s:26:"sfwd-quiz_prerequisiteList";s:0:"";s:16:"sfwd-quiz_course";i:0;s:16:"sfwd-quiz_lesson";i:0;s:22:"sfwd-quiz_prerequisite";s:0:"";s:28:"sfwd-quiz_retry_restrictions";s:0:"";s:17:"sfwd-quiz_repeats";s:0:"";s:25:"sfwd-quiz_quizRunOnceType";s:0:"";s:27:"sfwd-quiz_quizRunOnceCookie";s:0:"";s:27:"sfwd-quiz_passingpercentage";i:80;s:21:"sfwd-quiz_certificate";s:0:"";s:19:"sfwd-quiz_threshold";s:0:"";s:33:"sfwd-quiz_quiz_time_limit_enabled";s:0:"";s:19:"sfwd-quiz_timeLimit";s:1:"0";s:30:"sfwd-quiz_forcingQuestionSolve";b:0;s:21:"sfwd-quiz_quizRunOnce";b:0;s:32:"sfwd-quiz_quiz_materials_enabled";s:0:"";s:24:"sfwd-quiz_quiz_materials";s:0:"";s:24:"sfwd-quiz_custom_sorting";s:2:"on";s:19:"sfwd-quiz_autostart";b:0;s:28:"sfwd-quiz_showReviewQuestion";b:0;s:25:"sfwd-quiz_quizSummaryHide";b:1;s:30:"sfwd-quiz_skipQuestionDisabled";b:1;s:24:"sfwd-quiz_sortCategories";b:0;s:24:"sfwd-quiz_questionRandom";b:1;s:25:"sfwd-quiz_showMaxQuestion";s:0:"";s:30:"sfwd-quiz_showMaxQuestionValue";i:0;s:20:"sfwd-quiz_showPoints";b:0;s:22:"sfwd-quiz_showCategory";b:0;s:38:"sfwd-quiz_hideQuestionPositionOverview";b:0;s:31:"sfwd-quiz_hideQuestionNumbering";b:0;s:24:"sfwd-quiz_numberedAnswer";b:0;s:22:"sfwd-quiz_answerRandom";b:1;s:19:"sfwd-quiz_quizModus";i:3;s:45:"sfwd-quiz_quizModus_multiple_questionsPerPage";i:5;s:38:"sfwd-quiz_quizModus_single_back_button";s:0:"";s:35:"sfwd-quiz_quizModus_single_feedback";s:3:"end";s:21:"sfwd-quiz_titleHidden";b:1;s:28:"sfwd-quiz_resultGradeEnabled";b:0;s:20:"sfwd-quiz_resultText";s:0:"";s:30:"sfwd-quiz_btnRestartQuizHidden";b:1;s:27:"sfwd-quiz_showAverageResult";s:0:"";s:27:"sfwd-quiz_showCategoryScore";s:0:"";s:26:"sfwd-quiz_hideResultPoints";b:0;s:35:"sfwd-quiz_hideResultCorrectQuestion";b:0;s:28:"sfwd-quiz_hideResultQuizTime";b:0;s:30:"sfwd-quiz_hideAnswerMessageBox";b:0;s:28:"sfwd-quiz_disabledAnswerMark";b:0;s:31:"sfwd-quiz_btnViewQuestionHidden";b:0;s:32:"sfwd-quiz_custom_answer_feedback";s:2:"on";s:36:"sfwd-quiz_custom_result_data_display";s:0:"";s:37:"sfwd-quiz_associated_settings_enabled";s:0:"";s:35:"sfwd-quiz_toplistDataShowIn_enabled";s:0:"";s:34:"sfwd-quiz_statisticsIpLock_enabled";s:0:"";s:18:"sfwd-quiz_quiz_pro";s:3:"'.$new_quiz_id.'";s:23:"sfwd-quiz_formActivated";b:0;s:26:"sfwd-quiz_formShowPosition";s:1:"0";s:35:"sfwd-quiz_toplistDataAddPermissions";s:1:"1";s:32:"sfwd-quiz_toplistDataAddMultiple";b:0;s:29:"sfwd-quiz_toplistDataAddBlock";i:0;s:33:"sfwd-quiz_toplistDataAddAutomatic";b:0;s:30:"sfwd-quiz_toplistDataShowLimit";i:0;s:25:"sfwd-quiz_toplistDataSort";s:1:"1";s:26:"sfwd-quiz_toplistActivated";b:0;s:27:"sfwd-quiz_toplistDataShowIn";i:0;s:28:"sfwd-quiz_toplistDataCaptcha";b:0;s:22:"sfwd-quiz_statisticsOn";b:1;s:31:"sfwd-quiz_viewProfileStatistics";b:1;s:26:"sfwd-quiz_statisticsIpLock";i:0;s:23:"sfwd-quiz_email_enabled";s:0:"";s:29:"sfwd-quiz_email_enabled_admin";s:0:"";s:27:"sfwd-quiz_emailNotification";i:0;s:31:"sfwd-quiz_userEmailNotification";b:0;s:33:"sfwd-quiz_timeLimitCookie_enabled";s:0:"";s:25:"sfwd-quiz_timeLimitCookie";s:0:"";s:27:"sfwd-quiz_templates_enabled";s:0:"";}');

5
  • If everything comes out ok with get_post_meta, why does it matter? Probably you should only be accessing this field through the WP interface, i.e. the _post_meta() commands. I haven't looked at how/why it's stored like this but it looks like a datatype being added in some cases. Do you have a specific problem you're trying to solve?
    – mozboz
    Jul 10 '20 at 17:24
  • The plugin I am using won’t recognise the meta_value. If I remove the extra characters in phpmyadmin, then it works fine. I am writing some custom code to add functionality to LearnDash. And it is The LearnDash plugin that needs the data in the format including the : and ; characters Jul 10 '20 at 17:32
  • 1
    The meta field you are trying to update is serialized - that's what the color and curly braces mean. It's not working because you're trying to add values manually without serializing them, and since the code accessing the meta doesn't see the data in a format it expects, it doesn't know what to do with it.
    – WebElaine
    Jul 10 '20 at 19:19
  • But when I go into phpmyadmin and remove the s:##:" and the "; from either end, the meta_value works perfectly, so is there a way to create it withoutt haveing these bits added. Jul 10 '20 at 19:49
  • 1
    As I said, you should not (and no other code such as plugins) should be accessing this field directly. Use the _post_meta WP functions to access this field only, as they take care of adding and removing this serialisation. If you are using these functions but you don't get out what you put in, then there's a bug with those functions
    – mozboz
    Jul 10 '20 at 23:23

Your Answer

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

Browse other questions tagged or ask your own question.