当前位置: 动力学知识库 > 问答 > 编程问答 >

wordpress - Use value inside another PHP function

问题描述:

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?

网友答案:

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')); ?>
分享给朋友:
您可能感兴趣的文章:
随机阅读: