• Resolved robthirlby

    (@robthirlby)


    Hi, I’m completely baffled by this plugin. How do I encode an array value in a custom option? I’ve tried a serialized array and various comma and => separated formats without success.
    A simple example would be a great help.

Viewing 1 replies (of 1 total)
  • Plugin Author Leo Caseiro

    (@leocaseiro)

    Hi @robthirlby,

    Thanks for using Custom Option Plus and for your issue.

    The idea of get_customs() is to have the same key for each value of your array.

    Example:
    Example Array

    So you can read with:
    <?php $users = get_customs('users'); ?>

    However, if you’d like to import from another resource or just set as a single item, you can use json and, you can read with get_custom and json_decode, like so:

    JSON Example

    JSON Example:
    {"users": [{"firstname": "Leo", "lastname": "Caseiro"}, {"firstname": "Matt", "lastname": "Mullenweg"}, {"firstname": "Rob", "lastname": "Thirlby"}]}`

    Note: On my example, my key is list

    To get, use json_decode();

    <?php
        $list = json_decode(get_custom('list'));
        print_r($list->users);
    ?>
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
    • This reply was modified 8 years, 3 months ago by Leo Caseiro.
Viewing 1 replies (of 1 total)
  • The topic ‘array option’ is closed to new replies.