Displaying Custom Field Attributes on Frontend in Custom Template File

Home Forums Calendar Products Events Calendar PRO Displaying Custom Field Attributes on Frontend in Custom Template File

Viewing 15 posts - 31 through 45 (of 58 total)
  • Author
    Posts
  • #14821
    Ken
    Participant

    Is there a function to check if there is nothing selected or a certain value is selected that it doesn’t display the label/field value? I have field label “Duration” set with: none, 30 min, 45 min, 60 min.

    I tried:

    $my_dur = 'none';
    if (tribe_get_custom_field('Duration') != $my_dur):
    // show table row...Skip if duration is 'none'
    endif;
    // show next table row...

    #14830
    Jonah
    Participant

    Hey Ken, yeah you should be able to use what you’re using with a slight modification, try this:


    if (tribe_get_custom_field('Duration') != ''):

    echo tribe_get_custom_field('Duration');

    endif;

    #14831
    Ken
    Participant

    Johan,

    That would work fine for a text field if no data is entered, but I am using a drop down for the custom fields and by default the first item in a dropdown is always selected/used after updating/publishing an event.

    So I used “none” as my first item, but I cant get this to work..

    tribe_get_custom_field('Duration') !='none'

    #14855
    Jonah
    Participant

    Hi Ken,

    I’m not sure how to check against select values with the function. I’m going to get another dev to chime in here…

    #14877
    Reggie
    Participant

    Hi Jonah,
    I’m not having any luck with tribe_custom_field(‘Label Name’). Is this supposed to pull only the value of the custom field for 1 particular label?

    #14883
    Jonah
    Participant

    Hi Reggie, yes it should echo the custom events field with the label you specify.

    #14962
    moderntribe
    Participant

    Hi, Ken!

    I think I figured it out. The current version of the plugin is not stripping the values of their newlines/carriage returns (which is how you make the list of list items in the admin). You should be able to use comparison operators as follows (if my testing is correct):
    $my_dur = 'none\r\n';

    if (tribe_get_custom_field('Duration') != $my_dur):
    Alternatively, you could edit events-calendar-pro/admin-views/event-meta where the line reads:

    and make it read:

    Let me know if either solution works for you. Good luck!

    – Paul

    #14963
    moderntribe
    Participant

    Grr…. still getting used to these forums.

    Alternatively…
    $options = explode("\n", $customField['values'])

    Make it read

    $options = explode("\r\n", $customField['values'])

    Sorry about that!

    #14986
    Rob
    Member

    Thanks Paul!

    Ken: let us know if you’re still having issues from there.

    #15009
    Ken
    Participant

    I have tried both of the options here, although I am a bit hesitant to do the 2nd solution since it would be overwritten on the next upgrade. Correct?

    Needless to say I was not able to get the value not appear in when viewing the list.

    Here is a link to the pastebin with the code section I am using:
    http://pastebin.com/ZcnGv89c

    #15025
    Rob
    Member

    Hi Ken. Thanks for the follow-up; I’ll have Paul take another look when he hits the forums next.

    #15093
    Ken
    Participant

    Thanks Rob,

    Not sure if this is a issue or not, but is there an extra ‘>’ in line #29 before the last php echo call?

    #15115
    moderntribe
    Participant

    Hi, Ken.

    Option one seemed to be a fix that worked on my end… Hmm, it’s possible that you may have inserted other spurious whitespace around the options (spaces, tabs). You might consider doing a var_dump() and trying to figure out what whitespace is there, because I can almost guarantee that is the issue (e.g. it might be “none \r\n”). Try dumping the variable and seeing if you can tell what might be its current value including whitespace and then try the first option a few ways. Good luck, keep us posted!

    – Paul

    – Paul

    #15176
    Ken
    Participant

    Hi Paul. I have checked, recheck and checked again…Here are my results.

    I reset the event-meta.php to its default:
    $options = explode("\n", $customField['values'])

    Created an event and published with the initial selection in the dropdown ‘None’.

    The var_dump() returned this: ‘None\r\n’

    I then put this in my template:
    if (tribe_get_custom_field('Duration') !='None'): Unsuccessful.

    I then tried:
    if (tribe_get_custom_field('Duration') !='None\r\n'): Unsuccessful.

    I then went back to the event-meta.php and changed the line to:
    $options = explode("\r\n", $customField['values'])

    I then went back to the post and updated it with the initial select chosen in order to update the database.

    The var_dump() returns this now: ‘None’

    I then put this in my template:
    if (tribe_get_custom_field('Duration') !='None'): Success!

    I could not get this to function without modifying the core. I tried all variations: (‘none\r\n’, ‘none \r\n’, ‘none \n’, ‘none \r’, etc.) with the core unchanged. I can only think that maybe you had a modified core file and/or did not re-publish the event to update the value of the custom field in the database? Or I am a complete bonehead and am missing something here (which is highly more likely)

    Will this be considered a bug and changed or will I have to make the edits on the event-meta.php file for future upgrades?

    #15203
    Ken
    Participant

    Just to clarify, I tried all variations: (‘None\r\n’, ‘None \r\n’, ‘None \n’, ‘None \r’, etc.)

    I could not edit my comment.

Viewing 15 posts - 31 through 45 (of 58 total)
  • The topic ‘Displaying Custom Field Attributes on Frontend in Custom Template File’ is closed to new replies.