Home › Forums › Calendar Products › Events Calendar PRO › Displaying Custom Field Attributes on Frontend in Custom Template File
- This topic has 57 replies, 12 voices, and was last updated 12 years ago by Jonah.
-
AuthorPosts
-
February 7, 2012 at 1:17 pm #14821KenParticipant
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...
February 7, 2012 at 2:07 pm #14830JonahParticipantHey 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;
February 7, 2012 at 3:28 pm #14831KenParticipantJohan,
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'
February 8, 2012 at 9:02 am #14855JonahParticipantHi 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…
February 8, 2012 at 11:51 am #14877ReggieParticipantHi 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?February 8, 2012 at 2:34 pm #14883JonahParticipantHi Reggie, yes it should echo the custom events field with the label you specify.
February 9, 2012 at 1:58 pm #14962moderntribeParticipantHi, 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
February 9, 2012 at 2:00 pm #14963moderntribeParticipantGrr…. still getting used to these forums.
Alternatively…
$options = explode("\n", $customField['values'])
Make it read
$options = explode("\r\n", $customField['values'])
Sorry about that!
February 10, 2012 at 7:52 am #14986RobMemberThanks Paul!
Ken: let us know if you’re still having issues from there.
February 10, 2012 at 4:37 pm #15009KenParticipantI 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/ZcnGv89cFebruary 10, 2012 at 7:02 pm #15025RobMemberHi Ken. Thanks for the follow-up; I’ll have Paul take another look when he hits the forums next.
February 13, 2012 at 12:37 pm #15093KenParticipantThanks Rob,
Not sure if this is a issue or not, but is there an extra ‘>’ in line #29 before the last php echo call?
February 13, 2012 at 5:42 pm #15115moderntribeParticipantHi, 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
February 14, 2012 at 10:53 am #15176KenParticipantHi 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?
February 14, 2012 at 2:33 pm #15203KenParticipantJust to clarify, I tried all variations: (‘None\r\n’, ‘None \r\n’, ‘None \n’, ‘None \r’, etc.)
I could not edit my comment.
-
AuthorPosts
- The topic ‘Displaying Custom Field Attributes on Frontend in Custom Template File’ is closed to new replies.