Custom Fields
Re-Envisioned
Support MB Custom Post Type Use Checkbox Custom Type and When Checked Show Icon on Frontend

  • Creator
    Topic
  • #30095
    Resolved dwayne@theolivermediagroup.com
    Participant

    Hello,
    I'm creating a tournament registration form. One of my custom field options is gender:

    1. Boys
    2. Girls

    Whenever one is checked I want to show an icon (image) on the frontend.

    Can that be done? if so how?

Viewing 10 replies - 1 through 10 (of 14 total)
  • Author
    Replies
  • #30096
    Long Nguyen
    Moderator

    Hi,

    Do you mean to show an icon/image on the frontend form when creating a new tournament? Or show an icon/image on the single tournament page after creating a post?

    #30098

    Hello.
    Yes, to your second question "Show an icon/image on the single tournament page after creating a post".

    Can that be done?

    Thanks

    #30101
    Long Nguyen
    Moderator

    Hi,

    When outputting the field value, you can check it in a condition and show an icon/image as well. For example

    $value = rwmb_meta( 'boys_checkbox' );
    // If field is checked.
    if ( $value ) {
        echo 'Your image here';
    }
    

    Get more details on the documentation https://docs.metabox.io/fields/checkbox/#template-usage

    #30103

    Question, I see you provided the PHP Code, how would this look using the tool in WordPress?

    Thanks

    #30105

    Here's a screenshot of what I have - https://cln.sh/Wq5sdH

    If girls is checked - I want to show a girl icon
    If boys is checked - I want to show a boy icon
    if both is checked - I want to show an image that has both girls and boys

    Can that be done?

    #30140
    Long Nguyen
    Moderator

    Hi,

    It can be done if you use more conditions

    $value = rwmb_meta( 'gender' );
    if ( $value == 'boys' ) {
        echo 'Boys image here';
    }
    
    if ( $value == 'girls' ) {
        echo 'Girls image here';
    }
    ...
    

    Just the basic condition of PHP code, so please read more here https://www.php.net/manual/en/control-structures.if.php

    #30170

    I know this might be a dumb question. But where in the tool should I post this code? Here's a screenshot showing the "advance" section of the custom field - https://cln.sh/ZPKP2J

    Thanks for all the help

    #30189
    Long Nguyen
    Moderator

    Hi,

    You need to add the code to your theme's post template file. Please read more on the documentation https://docs.metabox.io/displaying-fields/#using-code

    #30197

    Hmmm...I'm still not clear on where to post the php code and the link you provided really isn't helping me.

    Here's a screenshot of my template directory - https://cln.sh/Ps69cc

    Can you PLEASE help me get this code posted so I can check this box off?

    Thanks

    #30207
    Long Nguyen
    Moderator

    Hi,

    You can add the code to the post template file of the theme. single.php is a good started file to understand how Meta Box output the field value. Or you can contact your theme support to ask for adding the code to the template files.

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