简体   繁体   中英

Use value inside another PHP function

In WordPress i'm currently using this function from a plugin <?php the_field('event_boat'); ?> <?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(); ?> <?php echo get_permalink(); ?> to get the permalink based on the post ID?

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'));

This should work fine. :)

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

This should work fine. :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM