I’m trying to implement the following guide to my custom wordpress theme http://tomsbigbox.com/wordpress-load-more-posts-on-page-scroll/
Unfortunately I have problems to include metabox and term values into the PHP variable.
How can I add/echo a variable inside of another variable? I hope I’m clear enough.
<?php
// .. wordpress function ... (have_posts()) : while (have_posts()) : the_post();
// Metabox
$email = get_post_meta( $post->ID, '_rsd_email', true );
// Taxonomy Term
$city = get_rsdt_terms('city');
$item = '<li>
<a id="itemn-'. get_the_ID() .'" href="'. get_permalink($post->ID) .'" title="'. get_the_title() .'">
<span>
<div class="role sixcol">
<h3>'. get_the_title() .'</h3>
<h4>'. $email .'</h4>
<span></span>
</div>
<div class="location threecol"><span>'. $city .'</span></div>
</span>
</a>
</li>';
// wordpress .....
?>
The simplest answer to this is to add some debugging statements to your script to output the contents of the variables. The variables are fully accessible within the scope of the script unless they are encapsulated within a function or class.
The most commonly used statement is to pass the variable into the print_r() function. So you would do something like “
print_r($city);” to get the contents of that.I, personally, like to use a slightly more extensive version of that command that ensures it outputs the results in a cleaner, more easily read fashion. Here is what I normally write.
The tags ensure that the browser renders the spaces and line breaks from the output. The “\n” and
that you see makes sure that it does both browser rendered line breaks before and after and source output line breaks.
You can do this with pretty much any variable type. The only times I have run into an issue with the output of a variable is if the variable is actually (or contains) a resource. An example of that is when outputting SimpleXML variables.