0

In WordPress i'm currently using this function from a plugin <?php the_field('event_boat'); ?> to output the post ID for the selected field, which happens to be 5755 in this example.

As the plugin only allows me to output the post ID is it possible to incorporate the value from that function inside <?php echo get_permalink(); ?> to get the permalink based on the post ID?

4 Answers 4

1

You can pass the ID as a parameter in the get_permalink function, either by storing the ID value in a new variable, or just passing in the ACF-function directly as a parameter.

$post_id = get_field('event_boat');
echo get_permalink($post_id) // echoes out link for ID 5755

I'm using get_field() instead of the_field() because the_field() will echo out the value, We just want to pass it along. We might aswell just do:

echo get_permalink(get_field('event_boat'));
Sign up to request clarification or add additional context in comments.

Comments

1

This should work fine. :)

<?php $a = get_permalink(get_field('event_boat')); echo $a; ?>

Comments

1
<?php $a =get_permalink(get_field('event_boat')); echo $a; ?>

Comments

0

This should work fine. :)

<?php echo get_permalink(get_field('event_boat')); ?>

1 Comment

Thank you very much! As you are both correct i'll have to accept the other answer as @ninja was first, but thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.