How can I find the name of a custom field?

Home Forums Calendar Products Events Calendar PRO How can I find the name of a custom field?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #73671
    Oliver
    Participant

    Hi,

    I added some custom fields and want to print them via php in an RSS feed – like this:
    echo tribe_get_custom_field(‘_ecp_custom_1’, $post_id);

    Unfortunately I only get back an empty string!
    I guess that the name of the custom field used is wrong. I had a look in the source code of the site and tried the id (“tribe_custom_rechteinhaber-name-des-fotografen-bei-foto-upload-anzugeben”) and name (“_ecp_custom_1”), but both didn’t worked.

    How can I find the correct name of the custom field?

    Best regards,
    Oliver

    #73887
    Oliver
    Participant

    Hi guys!

    I also tried this, but only got back an empty array:
    print_r(tribe_get_custom_fields( get_the_ID() ));

    Can someone give me a hint what’s wrong?

    Best regards,
    Oliver

    #73903
    Barry
    Member

    Hi Oliver,

    So long as you’re already within the loop it should work pretty much as you seem to be using it. My only comment would be that if your field is named “Human Readable” then that is what you should pass as the parameter, rather than “human-readable”, example:

    echo tribe_get_custom_field('Human Readable');

    In your case you are passing in the post ID – are you certain it is correct? The only other consideration is that tribe_get_custom_field() is geared toward retrieving additional fields in the Events Calendar PRO sense. If you are actually trying to use regular WordPress custom fields then you should use the relevant WordPress API functions.

    Does that help at all?

    #74057
    Oliver
    Participant

    Hi Barry,

    The $post_id works definitly (I set it and print it out a line before) 😉

    I had a look in the Events->Admin page (thanks for that hint, a very useful page!) and found the following:

    custom-fields =
    Array
    (
    [0] => Array
    (
    [name] => _ecp_custom_1
    [label] => Rechteinhaber
    [type] => text
    [values] =>
    )

    [1] => Array
    (
    [name] => _ecp_custom_2
    [label] => E-Mail Adresse für Rückfragen (Adresse wird nicht veröffentlicht)
    [type] => text
    [values] =>
    )
    }

    From my point of view the filed “name” should be the parameter I should pass to the function. Am I wrong? Nevertheless I tried the “Human Readable” as the parameter, but it didn’t worked.

    Best regards and thanks for your support!
    Oliver

    #74504
    Oliver
    Participant

    Hi Barry,
    do you have any news for me regarding this issue? Can you check with your development team to get an answer soon, please?
    Best regards,
    Oliver

    #74571
    Barry
    Member

    So again can you try using the ‘human readable’ form (the label)? In your case:

    $field_label = 'E-Mail Adresse für Rückfragen (Adresse wird nicht veröffentlicht)';
    $result = tribe_get_custom_field($field_label);

    #74892
    Oliver
    Participant

    Now it works! If found the problem 🙂

    The documentation is wrong! It says that the functions returns a string, but it returns an array (that’s a big difference! “echo” prints out nothing if a array is given):
    http://docs.tri.be/Events-Calendar-PRO/function-tribe_get_custom_field.html
    Please correct the documentation!

    The working code is as follows:
    $field_label = ‘E-Mail Adresse für Rückfragen (Adresse wird nicht veröffentlicht)’;
    $cpy = tribe_get_custom_fields($post_id, $field_label);
    echo $cpy[$field_label];

    Best regards and good night!
    OlIver

    #75011
    Barry
    Member

    Hi Oliver,

    Sounds like you arrived at a solution which is great.

    I’d point out though that tribe_get_custom_field() – which does indeed return a string – is a different function from tribe_get_custom_fields() (note the final s in the function name) – which is what you are using in your above example and is correctly documented as returning an array.

    Since it sounds like you’re all set in any case I’ll go ahead and close this thread – of course if there is anything else please don’t hesitate to create new threads as needed.

    Thanks!

    #981896
    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 9 posts - 1 through 9 (of 9 total)
  • The topic ‘How can I find the name of a custom field?’ is closed to new replies.