• Resolved Andujita

    (@andujita)


    Hello!

    I’m trying to use a checkbox_list at backend but It only returns at frontend one value while I need all the checked values.

    My code at frontend is something like that:

    <?php
    $beach_locations = rwmb_meta(‘easybeach’, $post->ID);
    foreach($beach_locations as $beach_location){
    echo $beach_location;
    };
    ?>

    And I get that error: “Warning: Invalid argument supplied for foreach() in /homepages/1/d355829528/htdocs/oceanicrentals/web/wp-content/themes/oceanic/single-rental.php on line 126”

    And when I put this code instead:

    <?php
    $beach_locations = rwmb_meta(‘easybeach’, $post->ID);
    echo $beach_locations;
    ?>

    I get only one of the values shown. What am I doing wrong?

    Thanks in advance!

    Antonio

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi,

    Can you try:

    <?php
    $beach_locations = rwmb_meta( 'easybeach', '', $post->ID );
    foreach ( $beach_locations as $beach_location ) {
        echo $beach_location;
    }
    ?>

    The helper function takes the post ID as the third parameter, not the second one. For more details, please see the documentation.

    • This reply was modified 6 years, 4 months ago by Anh Tran.
    Thread Starter Andujita

    (@andujita)

    Hi!

    Thanks for your reply but I still have the problem.

    Thread Starter Andujita

    (@andujita)

    Hi again,

    I have put this code as you suggested:

    $beach_locations = rwmb_meta( ‘easybeach’, ”, $post->ID );
    foreach ( $beach_locations as $beach_location ) {
    echo $beach_location;
    }

    But I still have the same problem. It is strange because I can get one value writing this:

    $beach_locations = rwmb_meta( ‘easybeach’, ”, $post->ID );
    echo $beach_locations;

    So the bug should be in other place or in your side.

    Antonio.

    Plugin Author Anh Tran

    (@rilwis)

    Looks like the helper function returns a single value instead of an array. So, can you please confirm that: do you register meta boxes under some condition like is_admin() or inside another hook? I mean do you just put the code:

    add_filter( 'rwmb_meta_boxes', 'your_function' );

    right in your theme’s functions.php file or in your plugin file without any condition?

    If you do, then please remove all the conditions. The conditions might prevent the plugin to get the field settings in the frontend. And in that case, it fallback to just get_post_meta(), which returns only 1 value.

    Thread Starter Andujita

    (@andujita)

    Ok it’s working now with the last code you sent me. It could be a nice idea to advise that this can happen in the support documentation of your website.

    Thanks!!!

    Plugin Author Anh Tran

    (@rilwis)

    Thanks, I’ve just updated the docs, adding the note for it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Checkbox_list only returns one value and not an array of values’ is closed to new replies.