Create a custom field that will be used for an external hyperlink link


I have found one forum thread that suggested a method to use the content from a custom field to generate a hyperlink but I cant quite get it too function as i need it.

The thread was

The suggested link method code was:

<a href="<?php echo do_shortcode('[ct id="_ct_radio_Field_ID" ]'); ?>" ><?php echo do_shortcode('[ct id="_ct_radio_Field_ID" ]'); ?></a>

I have tried this using my own unique custom field ID - ct_Event_Book_text_77e2 - but I can't use it to make my button "Book Tickets" link use the content from the field as the link destination.


  • Michael Bissett

    Hey @chris, hope you're doing well today! :slight_smile:

    Could you try using replacing this:

    <div class="wpmudevevents-bookinglink"><a href="<?php echo do_shortcode('[ct id="ct_Event_Book_text_77e2" ]'); ?>Buy Tickets</a></div>

    With this:

    <div class="wpmudevevents-bookinglink"><a href="<?php echo do_shortcode('[ct id="ct_Event_Book_text_77e2" ]'); ?>">Buy Tickets</a></div>

    And letting me know if that works for you or not?

    Please advise,

  • chris

    Hi Michael,

    I replaces the line with this as suggested:

    <div class="wpmudevevents-bookinglink"><a href="<?php echo do_shortcode('[ct id="ct_Event_Book_text_77e2" ]'); ?>Buy Tickets</a></div>

    But no change.

    A possible related issue stopping this working: Earlier on after reading through a few threads I tried to install a plugin Jack had set up but when I did it didnt appear to install properly - yet it would not let me re-install suggesting the folder already exists.

    I cant find any trace of it to remove it but I am concerned this may be affecting any code now written in custompress.

    Thanks for your assistance with this.

  • chris

    Hi Ash,

    Thanks so much that is perfect. It opens up many more uses of custompress for me as well so a big thanks.

    Could the same principle be used in the shortcode-archive-custom.php file to include a direct link from the search results?

    This currently uses the code:

    <section class="eab-events-archive <?php esc_attr_e($args['class']); ?>">
    <?php foreach ($events as $event) { ?>
    	<?php $event = $event instanceof Eab_EventModel ? $event : new Eab_EventModel($event); ?>
    	<article class="eab-event <?php echo eab_call_template('get_status_class', $event); ?>" id="eab-event-<?php echo $event->get_id(); ?>">
    <div class="eab-event-body">
    		<?php if ($event->has_featured_image()) { ?>
    <a href="<?php echo get_permalink($event->get_id()); ?> "class="customevent-image"><?php echo $event->get_featured_image('small'); ?></a>
    	<?php } ?>
    <a href="<?php echo get_permalink($event->get_id()); ?>" class="customevent-title"><h4><?php echo $event->get_title(); ?></h4></a>
    <div class="customevent-venue"><?php echo '' . $event->get_venue(); ?></div>
    <div class="customevents-contentmeta"><?php echo eab_call_template('get_archive_content', $event); ?></div>
    	<a href="<?php echo get_permalink($event->get_id()); ?>" class="wpmudevevents-viewcustomevent">Find out more</a>
    <?php } ?>

    I would like to float the Buy Tickets button to the right of the existing "Find out more" button.

    (This is a template file used by the shortcode on the page and I know those templates behave differently.)

    Thanks chris

  • chris

    Hi Ash,

    This is perfect again. Thank you.

    I want to make the Location display into a link on the single events page and will try to recreate this following this same principle.

    I don't think there is an automatic method to link the location field using Events+ (i would like to link it to a google map or similar) so will use the approach here using a unique custompress field to hyperlink it.

    If i get stuck i may ask more, but using custompress to create custom links is such a useful feature I plan to use over and over and I hope it help other users to. Thanks for your help with this.

    Many thanks

  • chris

    Hi Ash,

    This code worked to add a link but if no link was present the field did not show.

    Is it possible to make the link still show on the events page even if no link is added to the custom field?

    			$link = get_post_meta( $event->get_id(), 'ct_Event_Loca_text_fc36', true );
    			if( $link ) {
    			<a class="customevent-venue" href="<?php echo $link; ?>" target="_blank"><?php echo '' . $event->get_venue(); ?></a>
    			<?php } ?>

    I am aiming to make the venue detail on the single events page ( single-incsub_event.php behave in the same way as the venue detail on the list of events page ( shortcode-archive-custom.php ).

    Neither of these are set up yet. Can you please have a look and let me know.

    Many thanks

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.