Help Desk

Displaying Custom Field Attributes on Frontend in Custom Template File

  • Posts: 31 Topics: 7 Answers: 1
    | Permalink

    I created a custom field called “homeslider” , and the value for this is a URL to an image file.
    I want to show that image file in a jquery slider on the homepage of my site. I have the slider showing the 3 latest “Events” posts, but the images are not showing up using the normal get custom fields data.

    For these Events Custom Fields, are they being stored in the DB differently than normal custom fields meta data ?

    Please let me know what code needs to be used to pull out custom fields from the events posts.

    Thanks,
    Brian

    Posts: 31 Topics: 7 Answers: 1
    | Permalink

    sorry, here’s the pastebin link to view the code I’m using the pull the custom fields value (that normally works with standard custom fields on posts , but isn’t working with the way you’re storing events data )

    http://pastebin.com/rMieZWnf

    Posts: 31 Topics: 7 Answers: 1
    | Permalink

    Ok, I ended up looking through the database to see how these custom field values are stored in ECP 2.0 and found _ecp_custom_1 as the key….

    So for anyone looking for this answer, here’s the code I’m using to pull out the value for my first custom field value in the events custom fields – http://pastebin.com/bhFAZLFM

    Posts: 83 Topics: 2 Answers: 12
    | Permalink

    =)

    Thanks for posting the answer Brian!

    Posts: 28 Topics: 7 Answers: 2
    | Permalink

    Hey Brian,

    Would you happen to know how to display a custom field that has a link? (so how do I make it a link?)

    Posts: 28 Topics: 7 Answers: 2
    | Permalink

    Woops, found it…. (brain crash)

    <a href="ID, $key, true); ?>” rel=”bookmark”>ID, $key, true); ?>

    Posts: 5 Topics: 2
    | Permalink

    Shane,

    This could be more developer friendly if we could pass the field’s label as a sanitized id, instead of the cryptic _ecp_custom_1. Could that be lined up in a future release?

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Thanks for the suggestion, Reji. I’m reviewing this with our dev John now and if he thinks it’s worthwhile/easy to do, we’ll work it in for a future 2.x release. Appreciate the suggestion!

    Posts: 20 Answers: 4
    | Permalink

    Reji – would something like get_tribe_custom(‘Field label’) be sufficient?

    Posts: 28 Topics: 7 Answers: 2
    | Permalink

    Just as an example:

    On my event page I made tabs (event info, location, tickets, links, artists, etc)
    The ticket tab has 6 custom fields separated in two sections:

    Online Tickets
    Label: Field 1
    Label: Field 2
    Label: Field 3

    Instore Tickets:
    Label: Field 4
    Label: Field 5
    Label: Field 6

    I am still trying to figure out how to have the headers empty when there f.e. Field 4, 5, 6 are empty. So, if field 4 is empty, don’t show the Instore Tickets:

    If i do an ‘if’ function now like this:

    <?php $key = tribe_the_custom_fields( '_ecp_custom_1' );
    if ( trim( $key ) == "true" )
    {
    echo 'Online’;}
    }
    ?>

    I get ALL the custom fields again instead of the ones that I choose with:
    <a href="” rel=”bookmark” target=”blank”>
    <a href="” rel=”bookmark” target=”blank”>
    <a href="” rel=”bookmark” target=”blank”>

    Probably doing something wrong but yes get_tribe_custom(‘Field label’) would help us out a lot I guess

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Thanks Tineke. Let me run it by John, see if he thinks the get_tribe_custom(“field label”) approach would be worth working into the code base!

    Posts: 5 Topics: 2
    | Permalink

    John – yes, get_tribe_custom(‘Field label’) would definitely help.

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Looks like this would add value for a lot of folks. Since we’re on a code freeze for 2.0.2, I’m adding it as a 2.0.3 issue. Thanks all!

    Posts: 9 Topics: 7
    | Permalink

    Has anyone gotten this, get_tribe_custom(‘Field label’), to work in 2.0.3 …?
    Can you post an example of your code?

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Janet: I haven’t heard any reports of it, but let me get Jonah to confirm that it’s functional. Are you having problems getting it going on your end?

    Posts: 9 Topics: 7
    | Permalink

    Thanks for the reply Rob .. my question is in the usage.

    I have a custom field “website”.

    The built in function tribe_the_custom_fields(‘website’) returns the custom label and value properly. But I simply want to pull the value of field.

    Am I correct in assuming get_tribe_custom(‘website’) should return only the value? I get a function does not exist error.

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Hi Janet. You are correct in assuming that, but I know that just this morning we discovered an issue with get_tribe_custom that was giving us problems. I’m not positive of the specifics but I’ve asked our dev Jonah to take a look in case he has a suggestion to tide you over until we get the get_tribe_custom issue resolved in 2.1.

    Posts: 4021 Topics: 4 Answers: 763
    | Permalink

    Hi Janet,

    There is no function named get_tribe_custom(), it was decided to stick with naming convention and go with tribe_the_custom_fields() instead. If you just want to pull in the value of a field just use:

    $custom_field = tribe_the_custom_fields('FieldLabel');
    

    And then you can do what you want with $custom_field which will contain the value of your field. Does that help?

    Posts: 9 Topics: 7
    | Permalink

    Thanks Rob and Jonah!

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Happy to help, Janet. Do let us know if anything else comes up in the future and we’ll do what we can to assist.

    Posts: 4 Topics: 1
    | Permalink

    Hello! I’ve been listening to this thread over the past days now and trying out the custom fields option, however I think I’ve discovered a slightly error using the checkbox custom field…

    The situation is this;

    I’ve tied the events calendar up with a signup form, allowing my clients to accept signups to all events. Now in this case some events isn’t meant to get signups, so I went in added a custom checkbox field to be able to check that IF the event shouldn’t display a signup link.

    So it’s like an on/off switch, using “tribe_get_custom_fields” to see whether this checkbox is checked or not.

    Now once the custom checkbox field is checked and saved, it wont uncheck if you try to. Once you save it unchecked it will just go back to being checked, so it seems it’s not updating properly.

    Any ideas Rob, Jonah, anyone?

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Hey Haavard. Thanks for the note. Not sure about that; we’ll try and point you in the right direction on this, but no guarantees since it sounds like what you’ve done here is fairly customized to begin with. While I’m not sure what may be causing this, let me see if Jonah can help you out.

    Posts: 4021 Topics: 4 Answers: 763
    | Permalink

    Hey Haavard, you’re right this appears to be a bug. I’ll create a ticket for it and we’ll get it fixed ASAP. In the interim you may want to try using Advanced Custom Fields (http://www.advancedcustomfields.com/) for your purposes.

    Good luck!

    Posts: 4 Topics: 1
    | Permalink

    Thanks for the feedback Rob and Jonah! The Advanced Custom Fields work wonders, and was a great solution to this situation. Thanks for sending me in that direction. It turned out great!

    Posts: 4278 Topics: 105 Answers: 467
    | Permalink

    Awesome! Happy to help Haavard. If you need anything else please do let us know.

    Posts: 85 Topics: 24 Answers: 3
    | Permalink

    I am adding this to my template file for the listing:

    
    
    
    
    

    But this is what is returned:

    
    Duration:
    
    Duration:90 minutes
    
    
    
    

    Is there a way to return the just the value of the custom field instead of both the field label and the value? The method works fine for the single event page but the list template uses a table not a tag. Would the other choice be to re-write the list.php template file using instead of a ?

    Posts: 85 Topics: 24 Answers: 3
    | Permalink

    The post did not like the code.

    Here is a link to the code http://pastebin.com/cicLgGtV

    Posts: 4021 Topics: 4 Answers: 763
    | Permalink

    Hey Ken, we’ve got 3 functions available for event custom fields:

    – tribe_custom_field(‘Label Name’) – Echo Event Custom Field by Label
    – tribe_get_custom_field(‘Label Name’) – Get Event Custom Field by Label
    – tribe_get_custom_fields() – loops through all custom fields and builds an array of them
    – tribe_the_custom_fields() – loops through all custom fields and builds a definition list

    You’ll probably want to use tribe_custom_field(‘Label Name’).

    I hope that helps,
    Jonah

    Posts: 85 Topics: 24 Answers: 3
    | Permalink

    Thanks Jonah, I could not find those functions. That solved my issue.

    Posts: 4021 Topics: 4 Answers: 763
    | Permalink

    Glad that worked Ken, I’ll make sure to update the documentation so it’s there.