Support Forum
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.
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.
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.
Hi Dan,
You can contact Oxygen support to ask for getting post ID in the repeater component.
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.
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.
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.