using conditional statements for custom / additional fields?

Home Forums Calendar Products Events Calendar PRO using conditional statements for custom / additional fields?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1114818
    divcom_uk
    Participant

    Hi Folks- so i have a couple of custom fields at work and i’m hoping to do some visual stuff based on whether they’re populated or not.

    at the most basic i know to display them using this:
    <?php echo tribe_get_custom_field('Company'); ?>
    What i want to do is something more visual where i can display slightly more visual elements if the field is populated, and nothing if it’s empty.

    i tried the following (i’m trying to show some FontAwesome icons and style the text without creating empty elements if the fields aren’t populated) :

    <php if tribe_get_custom_field('Company'):?>

    <i class="fa fa-clock-o"></i> <?php echo tribe_get_custom_field('Company');?>

    <?php endif;?>

    This didn’t work- is there a way to achieve this? i do use the advanced custom fields but i’d rather use built-in functionality if available.

    Thanks in advance,
    Pete

    #1114932
    George
    Participant

    Hi Pete,

    Thanks for reaching out.

    ⚠️ We unfortunately cannot help with custom coding at all, so I will not be able to help see you through this custom coding question. Please read more about this here ? https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/


    With that being said, I would like to at least offer a bit of advice before having to close up this thread.

    First, tribe_get_custom_field() is a deprecated function. Do not use this any more. Use tribe_get_custom_fields() instead. This version of the function does NOT let you pass a specific field name, like ‘Company’. It returns the array of all custom fields for the given event.

    Next, to make it easier to check if the output of tribe_get_custom_fields(); is empty or not, I would recommend storing the output in a variable and then checking the value of that variable.

    So, something like this:


    $event_fields = tribe_get_custom_fields();

    That will make $event_fields have the value of the event custom fields. You can then check for the existence of a “Company” field in a number of ways.

    To learn how to do that, I would recommend first seeing what the output of $event_fields is for you. You can use the PHP debugging function var_dump() for that, or print_r(), like as follows:


    var_dump( $event_fields );


    print_r( $event_fields );

    Check out the output and tinker from there.

    You will have to take the reins from here, and we cannot help with further questions about this custom coding, but I hope this information helps you get started.

    You can learn more about var_dump() here, and can learn more about print_r() here. If you would like more assistance with the custom coding, you can hire a professional developer to assist you. We have a list of great developers here ? http://m.tri.be/18k1 (and we have no affiliation with any of these folks–they’re simply some well-respected names in the community that we’ve compiled).

    Best of luck with your customizing!
    George

    #1120695
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘using conditional statements for custom / additional fields?’ is closed to new replies.