Home › Forums › Calendar Products › Events Calendar PRO › tribe_get_custom_field – Depreciated need alternate.
- This topic has 4 replies, 2 voices, and was last updated 5 years, 7 months ago by Jennifer.
-
AuthorPosts
-
September 19, 2018 at 4:01 pm #1625906Ken CharityParticipant
We are using the custom field feature to create a URL field, Just that one custom field..
We were using is like so in our details.php file:
$register_cf = tribe_get_custom_field( 'Register' );
Then further down calling the variable like so:
<?php // Event Registration if ( ! empty( $register_cf ) ) : ?> <div class="mec-event-more-info"> <i class="mec-sl-info"></i> <dt> <?php esc_html_e( 'Registration:', 'the-events-calendar' ) ?> </dt> <dd class="tribe-events-event-url"><a href="<?php echo $register_cf;?>" class="x-btn x-btn-large" style="text-shadow:none;color:#ffffff;margin:0.5em 0;">Register Online</a></dd> </div> <?php endif ?>
Since the new function is now
tribe_get_custom_fields()
and brings an array over.How can I assign it to a variable? and for just the named field “Register”?
September 19, 2018 at 4:16 pm #1625919Ken CharityParticipantAfter some experimenting, I have updated my code to:
//Custom fields $fields = tribe_get_custom_fields(); $register_cf = $fields['Register'];
This gets the $register_cf to have the content of the field, but is wrapping it automatically in
<a>
tag so that I cannot correctly format it and have the classes I want. So then do I have to strip the string of its tags so I can insert it the way I want?September 20, 2018 at 6:27 pm #1626978JenniferKeymasterHello,
Thanks for reaching out!
To get the plain URL without any markup, try using this instead:
$field = get_post_meta( $event_id, '_ecp_custom_1' );
-You may need to change the 1 in “_ecp_custom_1” to the correct ID for your field, which you can grab by viewing the source on the Additional Fields tab of the settings (see “name” in this screenshot) or by looking through all of the post meta:
$field = get_post_meta( $event_id ); var_dump( $field );
We are limited in the amount of support that we can provide for customizations, but if you get stuck or have any questions, please let me know – I’ll be happy to try to point you in the right direction!
Thanks,
Jennifer
September 25, 2018 at 8:38 am #1630085Ken CharityParticipantThat didn’t help. Much easier to just use
strip_tags( $myvariable)
My Solution:
<?php //Custom fields $fields = tribe_get_custom_fields(); $register_cf = $fields['Register']; // Event Registration if ( ! empty( $register_cf ) ) : ?> <div class="mec-event-more-info"> <i class="mec-sl-info"></i> <dt><?php esc_html_e( 'Registration:', 'the-events-calendar' ) ?></dt> <dd class="tribe-events-event-url"><a href="<?php echo strip_tags( $register_cf );?>" class="x-btn x-btn-large">Register Online</a></dd> </div> <?php endif ?>
September 25, 2018 at 9:07 am #1630105JenniferKeymasterHi Ken,
I’m glad you found a better solution! If you run into any other issues, please don’t hesitate to reach out.
October 17, 2018 at 9:35 am #1644342Support DroidKeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘tribe_get_custom_field – Depreciated need alternate.’ is closed to new replies.