• Resolved timyc

    (@timyc)


    For example, I use a SQL query to retrieve data which is outputted as ‘a:1:{i:0;i:119;}’. How would I parse ‘119’ without calling any WordPress functions. I’m working on a headless WordPress project.

Viewing 1 replies (of 1 total)
  • What you are seeing there is a serilized PHP array. That’s how at least soem postmeta stuff is stored.

    When you see that, you can use this sort of code:

    $value = unserialize($meta);

    That will give you the array, and you can process it as you would any other array.

    I do have two tips though. Firstly, if you can, you can call get_post_meta() with ‘true’ at the end to get a single value instead of the array. That may or may not work for your situation. Secondly, there’s a great WordPress function of maybe_unserliaze() which will do everything for you without you needing to do any more checks.

Viewing 1 replies (of 1 total)
  • The topic ‘How do I parse postmeta meta_values with vanilla PHP’ is closed to new replies.