Reputation: 3075
I am working on a PHP loop for Wordpress and populating the content with variables.
Currently I have an echo to produce the HTML blocks for the loop that looks like this:
echo '<div class="col-sm-4 retailer" data-state="'.$state.'">
<div class="locationName">'.the_title().'</div>
<div class="locationAddress">'.the_field("address").'</div>
</div>';
However, in the outputted HTML the 2 variables(the_title and the_field("address")) are being placed below the content block instead of within their respective divs like this:
<div class="col-sm-4 retailer" data-state="Alaska">
<div class="locationName"></div>
<div class="locationAddress"></div>
</div>Location #1 81234 Sample Dr.
Can anyone tell me why the variables aren't being contained to the correct divs? Thanks!
Upvotes: 1
Views: 684
Reputation: 208
$title =the_title()
$address = the_field("address");
echo "<div class='col-sm-4 retailer' data-state='$state'>
<div class='locationName'>$title</div>
<div class='locationAddress'>$address</div>
</div>";
Upvotes: 0
Reputation: 3075
Here is the solution that ended up working for me based on tips from @ErkiA and @Twisted1919:
echo '<div class="col-sm-4 retailer" data-state="'.$state.'">
<div class="locationName">'.get_title().'</div>
<div class="locationAddress">'.get_field("address").'</div>
</div>';
get_title()
grabs the title of the Wordpress post and get_field("address")
retrieves the value from a custom field I've set up using Advanced Custom Fields.
Upvotes: 2