Custom Fields
Re-Envisioned
Support General Error using cloneable text field

  • Creator
    Topic
  • #32188
    Resolved Dan Smith
    Participant

    My wife teaches dancing. I've helped her keep track of the dances using Meta Box. Quite a few of the dances can be danced to more than one song.
    I have a text field with the id of music which is cloneable. As per your documentation I've added within a code block the code:

    <?php
        $values = rwmb_meta( 'music' ) ;
        foreach ( $values as $value ) {
            echo $value;
        }
    ?>

    I'm getting an error of:
    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/oxygen/component-
    framework/components/layouts/code-block.php(33) : eval()'d code on line 3
    On the frontend everything works as I'd like it to but the error plays havoc with my OCD.
    Am I doing something wrong, if not is there a work around? Any help with this would be greatly appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #32194
    Long Nguyen
    Moderator

    Hi,

    As on the documentation https://docs.metabox.io/rwmb-meta/
    If you do not pass the third parameter $post_id to the helper function, it will take the current post ID to get the field value. But somehow when you edit the post by Oxygen, the post ID is not retrieved. Maybe you are working with Templates, not editing the post itself.

    #32262
    Dan Smith
    Participant

    The code block is on a page. The problem, maybe that it is within an Oxygen Repeater. Tried adding the $post_id, checked online, some suggested a '&' in front of the $value, tried that.

    Same error, still working on frontend.

    #32274
    Long Nguyen
    Moderator

    Hi Dan,

    You can contact Oxygen support to ask for getting post ID in the repeater component.

    #32301
    Dan Smith
    Participant

    It's easy enough to get the post ID in a repeater. I have code in another plugin which causes the display of the id as a column when I display all the posts.

    Placing this code:

    <?php
        $postal =  get_the_id();
           echo $postal;
        $values = rwmb_meta( 'music', $postal ) ;
        foreach ( $values as $value ) {
            echo $value;
            echo '<br />';
        }
    ?>

    I get the display
    598I Don't Need the Booze by Alan Jackson
    Redneck Love Gone Bad by Diamond Rio
    You Turn Me On by Tim McGraw
    That Don’t Impress Me Much by Shania Twain

    598 Is the ID for that particular Post and each subsequent post has the correct ID as well yet I am still getting the error.

    #32311
    Long Nguyen
    Moderator

    Hi,

    Please pass the second parameter to the helper function, if you do not need to pass any value, just leave it blank.

    $values = rwmb_meta( 'music', '', $postal );
    

    Let me know how it goes.

    #32335
    Dan Smith
    Participant

    Been kind of distracted lately, just noticed that the other meta box fields were blank within the editor. I'm guessing the data isn't there until the repeater content is display on the frontend.

    I added

    <?php
       if (rwmb_meta( 'music', '', $postal )) : ; 
        $postal =  get_the_id();
        $values = rwmb_meta( 'music', '', $postal ) ;
        echo 'Music: ';
        foreach ( $values as $value ) {
             echo $value;
             echo '<br />';
        }
        endif;
    ?>

    Error is gone and everything works ok on the frontend.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.