Support

Account

Home Forums General Issues How to display a wp post from a custom field trigger in custom posts (events) Reply To: How to display a wp post from a custom field trigger in custom posts (events)

  • “Doesn’t this now have the single one-to-one relationship already established or do I need your above code to return the post ID?”

    What happens is that the relationship field stores an array of the selected Post IDs as meta data against the Event post. Since you’ve clamped the maximum number of posts to just one, there will only be one item in the array, but it’s still an array, as opposed to a single value. So, yes, you’d need code like the above, in order to pull get the related Post ID. The code basically pulls out the value against the key of ‘0’ from the array

    From that point on, I’d imagine you have two options. You could either use that Post ID to pull IN data from the related Post, and feed it into your single Event template, or you could use the Post ID to determine where to redirect someone when they click on the item in the calendar (so instead of seeing a standard event calendar item, they’re actually bounced to the Post that you made the relationship with).

    Looks like you want the latter – bounce to the Post

    From this point on, it’s really an Events Calendar Pro issue – something I’m not that familiar with – but I seem to remember that you could create custom versions of the standard template, so you could override the default output. What you’re looking to do is determine whether a particular Event post has a relationship to a standard Post, and if it does, change the target URL to that post, rather than the standard single Event post.

    Have a look here: http://tri.be/support/documentation/events-calendar-themers-guide/#customfiles

    Looks like you need to find the file that contains the link you want to change (single-event.php for each of the different views you’re going to use), and where it says something like <a href="<?php tribe_event_link($post); ?>" class="url"> (which I think is the link from the calendar view to the single event), you’ll have to get in there and use an IF statement to intervene, so that if there’s a related event, you use get_permalink() and the related Post ID we talked about earlier, to bounce the user to the related post instead

    instead of:

    <h3 class="tribe-events-month-event-title summary"><a href="<?php tribe_event_link($post); ?>" class="url"><?php the_title(); ?></a></h3>

    maybe something like (expanded for clarity):

        <h3 class="tribe-events-month-event-title summary">
        
        <?php if ($desired_post_id) { ?>
        
        	<a href="<?php echo get_permalink($desired_post_id); ?>" class="url">
        
        <?php } else { ?>
        
        	<a href="<?php tribe_event_link($post); ?>" class="url">
        
        <?php } ?>
        
        <?php the_title(); ?></a></h3>

    where $desired_post_id is the related ID we obtained earlier.

    Hope this is useful. It’s probably more of an Event Calendar Pro puzzle from this point on