Home › Forums › Calendar Products › Events Calendar PRO › Custom fields: formatting URL without changing the type to "text"
- This topic has 3 replies, 3 voices, and was last updated 9 years, 6 months ago by
Dinah.
-
AuthorPosts
-
October 9, 2016 at 11:10 am #1174286
Dinah
ParticipantUnfortunately I haven’t found a solution in the forum, although I found a lot of similar posts, but those solutions didn’t solve my problem.
I have a custom field named “Anmeldung” and it’s type is “URL” – I use this custom field to add an URL to an external registration page.
I found out, that custom fields with type = url have already the a href included – so as a result my URL that was entered will show up as:
<a href="https://external-website-for-registration.com" target="_blank">https://external-website-for-registration.com </a>that means the name of the link == URL :-/
What I tried to figure out was to get the Link like:
<a href="https://external-website-for-registration.com" target="_blank">Whatever I want to name the link</a>I found a post in the forum where it is recommended to change the type from URL to text to be able to modify it. That works nearly as expected 😉
$custom_fields = tribe_get_custom_fields(); $anmeldung_url = $custom_fields[ 'Anmeldung' ]; echo "<strong>Anmeldung</strong><br /><a href='$anmeldung_url' target='_blank'>zur Anmeldung</a>";Therefore I had to identify the specific custom_field (thank you, I also found some solutions in your forum to do this :-)) and I could build my link as preferred.
BUT…
Due to the fact that all custom fields are selected and displayed using the foreach loop I could not figure out how to “interrupt” this to modify the specific URL field.
<?php foreach ( $fields as $name => $value ): ?> <dt> <?php echo esc_html( $name ); ?> </dt> <dd class="tribe-meta-value"> <?php // This can hold HTML. The values are cleansed upstream echo $value; ?> </dd> <?php endforeach ?>I either have to accept that the URL will be listed twice (from the foreach part and afterwards from my specific request) or delete the foreach part and select each custom field separately.
I wonder if there isn’t a better solution to directly resolve this problem with the foreach loop? Because a second problem came up in case that I request each custom field separately – I couldn’t figute out how to get the Label.
In my solution I just entered the text in front of my echo, but this seem to be a bad solution, with reference to any changes that could be made.
Is there a way to get the custom field labels, too?
Many thanks in advance for your support!
DinahOctober 9, 2016 at 1:11 pm #1174306Dinah
Participant😀 I resolved it by myself!
<?php foreach ( $fields as $name => $value ): ?> <dt> <?php echo esc_html( $name ); ?> </dt> <dd class="tribe-meta-value"> <?php // prüfen ob das der Wert des Custom Fields = Anmeldung ist, dann Link formatieren if ( $value == $fields['Anmeldung'] ) { echo "<a href='$value' class='tribe-events-button' target='_blank'>Jetzt anmelden !</a>"; // andernfalls die Ausgabe ganz normal fortführen } else { echo $value; } ?> </dd> <?php endforeach ?>Many thanks, this ticket can be closed.
Best regards, Dinah
October 9, 2016 at 2:17 pm #1174322George
ParticipantGlad to hear it, Dinah!
-
AuthorPosts
- The topic ‘Custom fields: formatting URL without changing the type to "text"’ is closed to new replies.
