For whatever reason, I am unable to get Wordpress_Query to come back the custom area values of posts. I'm able to obtain the publish pictures using get_the_post_thumbnail($post->ID, array(50,50)), however i cannot obtain the custom area data using get_post_meta($post->ID, $key, true).
A removed-lower version of the items I am attempting to do:
<?php
$keys = array('Show Date','Birth Year','Origin');
echo '<table>';
echo '<tr><th>Title</th>';
foreach( $keys as $key ) {
echo '<th>' . $key . '<th>';
}
echo '</tr>';
$myquery = new WP_Query( 'post_type=post' );
if( $myquery->have_posts() ) : while( $myquery->have_posts() ) : $myquery->the_post();
$title = get_the_title();
echo '<tr><td>' . $title . '</td>';
$values = array();
foreach( $keys as $key ) {
$values[] = get_post_meta($post->ID, $key, true);
}
foreach( $values as $value ) {
echo '<td>';
echo $value;
echo '</td>';
}
echo '</tr>';
endwhile; endif;
echo '</table>';
?>
Available too here:
http://pastebin.com/at8S2THs
Despite all non-essential code removed, I am unable to get this to work. I understand you should use parameters like meta_key and meta_value inside a query to limit the outcomes, but Among the finest to show all values for that secrets I specify, when they exist, for every publish.
Any help could be greatly appreciated...
** SOLUTION FOUND **
Just required to add global $post; after the beginning of the loop. Because of @Kimikaze around the Wordpress discussion board for supplying the answer!
After I aren't able to find the information I want in wordpress, I usually think it is useful to print the worldwide $publish resist screen, in order to find out if my information is which makes it towards the page.
Global $post;
echo "<pre>";
print_r($post);
echo "</pre>";
All of the assistant techniques or "hooks" are often just getting together with this (or any other) global object. Look into the creation of this on $publish (and perhaps your $values array) for data you are searching for and when it's there, you can easily reffer into it directly, such as the publish title for instance
$post->title
Another thought, The 3rd parameter of get_publish_meta() causes it to be return just one string when set to true, exactly what do you receive when it is set to false?
I am speculating the issue has related to the values you are using as meta secrets. To retrieve the information with get_publish_meta() you will want to pass in the meta_key values, that are most likely 'show_date', 'birth_year', and 'origin' because the meta_key value does not handle uppercase letters or spaces. Try altering to individuals values where you are setting the $secrets array:
$keys = array('show_date','birth_year','origin');
In the event that does not work, it may be worth checking within the database (within the wordpress_postmeta table) to verify the particular meta_key values.