Forum Replies Created

  • That’s not really what ACF is meant for – it’s a system for creating custom content meta fields for posts in the WordPress back end, that then allows the content within those fields to be used on the front end. So it’s the content you add in the back end that’s available to the front end, not the actual fields themselves.

    It IS possible, with a bit of work, to set up a front end template, so that information the users input will create post data in the back end, but it’s not really a drag-and-drop to set up kind of thing:

    Sounds like you’d be better looking for a suitable forms plugin to use for this job (e.g. Gravity Forms)

  • “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:

    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

  • By default, the relationship field returns an array of post objects, so your $posts->post_name won’t return your desried post’s name. You’d have to dig into the array, or iterate through it. Or do something like set the relationship field to return an array of chosen post IDs instead, and pump THAT into your query using WP_Query’s ‘post__in’ parameter

  • If you’ve selected ‘Post IDs’ as the return format for your Relationship field, then get_field('page_link') (for example) will return an array of post IDs. If you clamp them down to just choosing ONE (by setting the Maximum Posts’ value to 1), then you can safely get your post ID by doing something like:

    $linked_post_ids_array = get_field('page_link'); // gets the array post post IDs
    $desired_post_id = $linked_post_ids_array[0]; // gets the ID of the 1st item in the array

    once you have the post ID, you can use a variety of WordPress and ACF functions to get related content,

    i.e. for an ACF field connected to the post, just pass the post ID:

    get_field('my_post_field', $desired_post_id);

    for general post info, you can use WordPress’ get_post

    $post_object = get_post($desired_post_id);

    hope this is enough info to point you in the right direction

  • Under ‘Location’, you can set rules to determine where the Field Group is shown. By default it will probably say ‘Show this field group if – Post Type – is equal to – post’, but you can select a different Custom Post Type in place of ‘post’ (or create much more complex rules if needed)

Viewing 5 posts - 1 through 5 (of 5 total)