Error using cloneable text field
- This topic has 6 replies, 2 voices, and was last updated 3 years, 4 months ago by
Dan Smith.
-
AuthorPosts
-
November 27, 2021 at 2:54 AM #32188
Dan Smith
ParticipantMy 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.November 27, 2021 at 3:18 PM #32194Long Nguyen
ModeratorHi,
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.November 29, 2021 at 10:56 PM #32262Dan Smith
ParticipantThe 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.
November 30, 2021 at 1:11 PM #32274Long Nguyen
ModeratorHi Dan,
You can contact Oxygen support to ask for getting post ID in the repeater component.
December 1, 2021 at 8:30 AM #32301Dan Smith
ParticipantIt'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 Twain598 Is the ID for that particular Post and each subsequent post has the correct ID as well yet I am still getting the error.
December 1, 2021 at 2:50 PM #32311Long Nguyen
ModeratorHi,
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.
December 2, 2021 at 12:41 AM #32335Dan Smith
ParticipantBeen 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.
-
AuthorPosts
- You must be logged in to reply to this topic.