wordpress - Combine these basic php functions

607

I need to add these two php functions<?php the_field('city'); ?> and<?php the_field('country'); ?> into the function below in place of the$city and$country variables.

<?php echo do_shortcode('[forecast location="' . $city . ' , ' . $country. '" caption="" numdays="3" iconset="Cartoon" class="css_table_class" cache="true"]'); ?>

Would appreciate any help my PHP isn't very good at all and I keep getting erros.

Thanks

478

Answer

Solution:

the_field outputs the field value instead of returning it. You needget_the_field:

echo do_shortcode(
    '[forecast location="' . get_the_field('city') . ' , ' . get_the_field('country') . 
    '" caption="" numdays="3" iconset="Cartoon" class="css_table_class" cache="true"]'
); 

People are also looking for solutions to the problem: jQuery mobile and PHP define variable

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.