PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Setting post_data value to an array

  1. Hi Guys,
    I'm sure I'm doing this wrong, but I'm stuck.

    I'm using pre_submission_filter to change the value of a hidden field to an array.

    $time = array( 'hours' => 2);
    $post_data['post_custom_fields']['_DURATION'] = $time;

    The problem is if I don't serialize the $time then _DURATION is set to 2 (the value of the first key in $time). If I do serialize $time then _DURATION is set to s:26;"a:1:{5:"hours;s:1"2";}"; (a serialized string of my serialized array :)

    Like I said, I'm sure I'm doing something really really wrong here, but I'm going mad trying to figure this one out.

    Can anyone help?

    Posted 8 years ago on Friday February 15, 2013 | Permalink
  2. Sounds like you want to store the array literally in a custom field called _DURATION. What should that value look like in the post_meta table? (do you have examples of values already stored there correctly?) I assume some other plugin or function needs the data in that format to function properly.

    Posted 8 years ago on Monday February 18, 2013 | Permalink
  3. Sorry for the slow response. For some reason I didn't receive an email notification about your posting.

    That is exactly correct. Sorry for the unclear posting earlier. Here's an example of how the value should look:
    http://prntscr.com/td7is

    Thanks for your help.

    Posted 8 years ago on Tuesday February 19, 2013 | Permalink
  4. Can you share the code you are using where it stores it as a serialized string if your serialized array? Seems like it's probably something small we need to do to make this work.

    Posted 8 years ago on Friday February 22, 2013 | Permalink
  5. Absolutely.

    http://pastebin.com/9rXUqGAa

    Also here is the link to the form (not sure if it matters):
    http://inland360.com/your-voice/submit-an-event/

    Thanks for your time.

    Posted 8 years ago on Friday February 22, 2013 | Permalink
  6. I never did find out the issue with this.

    I decided to make the call to update_post_meta() myself instead of relying on it happening somewhere else. This worked out just fine for my purposes.

    Thanks.

    Posted 8 years ago on Thursday February 28, 2013 | Permalink
  7. Thank you for the update.

    Posted 8 years ago on Monday March 4, 2013 | Permalink

This topic has been resolved and has been closed to new replies.