I currently have the following my_meta code:
function my_meta() {
if ( $keys = get_post_custom_keys() ) {
echo "<ul class='post-meta'>\n";
asort($keys);
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( '_' == $keyt{0} )
continue;
$values = array_map('trim', get_post_custom_values($key));
$value = implode($values,', ');
echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
}
echo "</ul>\n";
}
}
The code works fine when I insert it into a page and it displays all of the custom fields on that page. So, for example, on my Japan page, when I write <?php my_meta(); ?>, it displays all of the custom fields that I have on the Japan page.
What I am looking to do is to display all of the custom fields from Japan on a different page. I would like to display the Custom Fields from Japan onto a page called Asia.
Below is where I am having the problems.
function japan_numbers() {
if (is_page('6601')) {global $wpdb;
?>
<ul class="value">
<li><span><strong>** Click to view </strong></span></li></ul>
<ol class="total">
<li>Japan Value <span><?php echo get_post_meta(6918,'Total Value',true); ?></span></li>
</ol>
<h2 class="related_links">Values</h2>
<ul class="country_info">
<span>THIS IS WHERE I NEED HELP!!!!!! <?php $meta = get_post_meta( get_the_ID(6918 ALL CUSTOM FIELDS) ); ?></span>
</ul>
<?php
}}
add_action('thesis_hook_feature_box', 'japan_numbers');
As you can see, we can get a specific custom field from a page (the 6918, 'Total Value'), but I don't know how to grab ALL of the custom fields from a specific page, and display it on another page. It seems simple, but I just can't figure it out.
What I want is for the custom fields of 6918 to be displayed on page 6601 in the php code above.
Arnav Joy answers:
try this
<?php
function japan_numbers() {
if (is_page('6601')) {global $wpdb;
?>
<ul class="value">
<li><span>** Click to view </span></li></ul>
<ol class="total">
<li>Japan Value <span><?php echo get_post_meta(6918,'Total Value',true); ?></span></li>
</ol>
<h2 class="related_links">Values</h2>
<ul class="country_info">
<span>
THIS IS WHERE I NEED HELP!!!!!!
<?php //$meta = get_post_meta( get_the_ID(6918 ALL CUSTOM FIELDS) ); ?>
<?php
if ( $keys = get_post_custom_keys(6918 ) ) {
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( '_' == $keyt{0} )
continue;
$values = array_map('trim', get_post_custom_values($key));
$value = implode($values,', ');
echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
}
}
?>
</span>
</ul>
<?php
}}
add_action('thesis_hook_feature_box', 'japan_numbers');
vitaminman comments:
Hi, Thanks for answering. Unfortunately, it is not working.
This is what I have:
function japan_numbers() {
if (is_tag('japan')) {global $wpdb;
?>
<ul class="value">
<li><span><strong>** Click to view value source</strong></span></li></ul>
<ol class="total">
<li>Japan Black Market Value <span><?php echo get_post_meta(6918,'Total Country Black Market Value',true); ?></span></li>
</ol>
<h2 class="related_links">Country Values</h2>
<ul class="country_info">
<span><?php
if ( $keys = get_post_custom_keys(6918 ) ) {
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( '_' == $keyt{0} )
continue;
$values = array_map('trim', get_post_custom_values($key));
$value = implode($values,', ');
echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
}
}
?>
</span>
</span>
}
?>
</ul>
<?php
}}
add_action('thesis_hook_feature_box', 'japan_numbers');
And this is what is being displayed:
<blockquote>
Country Values
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Video Game Piracy:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Total Country Black Market Value:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Counterfeit Goods:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Drug Trafficking:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Movie Piracy:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Software Piracy:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Marijuana Price:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Cocaine Price:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Heroin Price:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Ecstasy Price:
Warning: array_map() [function.array-map]: Argument #2 should be an array in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4021
Warning: implode() [function.implode]: Invalid arguments passed in /home/content/27/7155927/html/wp-content/themes/thesis_185/custom/custom_functions.php on line 4025
Prostitution:
} ?>
</blockquote>
Any suggestions?
Arnav Joy comments:
try this
<?php
function japan_numbers() {
if (is_page('6601')) {global $wpdb;
?>
<ul class="value">
<li><span>** Click to view </span></li></ul>
<ol class="total">
<li>Japan Value <span><?php echo get_post_meta(6918,'Total Value',true); ?></span></li>
</ol>
<h2 class="related_links">Values</h2>
<ul class="country_info">
<span>
THIS IS WHERE I NEED HELP!!!!!!
<?php //$meta = get_post_meta( get_the_ID(6918 ALL CUSTOM FIELDS) ); ?>
<?php
if ( $keys = get_post_custom_keys(6918 ) ) {
foreach ( (array)$keys as $key => $value ) {
$valuet = trim($value);
if ( '_' == $valuet{0} )
continue;
echo "<li><span class='post-meta-key'>$key:</span>".$value."</li>\n";
}
}
?>
</span>
</ul>
<?php
}}
add_action('thesis_hook_feature_box', 'japan_numbers');
vitaminman comments:
So close.
This is what its showing now:
<blockquote>Country Values
0:Video Game Piracy
4:Total Country Black Market Value
5:Counterfeit Goods
6:Drug Trafficking
7:Movie Piracy
8:Software Piracy
9:Marijuana Price
10:Cocaine Price
11: Heroin Price
12:Ecstasy Price
13:Prostitution
</blockquote>
So its catching the Custom Field Name, but not the value.
Arnav Joy comments:
replace this line
echo "<li><span class='post-meta-key'>$key:</span>".$value."</li>\n";
with these two
$custom_value = get_post_meta(6918 , $value , true)
echo "<li><span class='post-meta-key'>$key:</span>".$custom_value."</li>\n";
Arnav Joy comments:
replace this line
echo "<li><span class='post-meta-key'>$key:</span>".$value."</li>\n";
with these two
$custom_value = get_post_meta(6918 , $value , true);
echo "<li><span class='post-meta-key'>$key:</span>".$custom_value."</li>\n";
vitaminman comments:
Now only the values are showing:
<blockquote>Country Values
0:$10700 Million ($10.7 Billion)
4:$108.3 Billion
5:$75 Billion
6:$9.3 Billion
7:$732 Million
8:$1875 Million ($1.875 Billion)
9:$68.4 per gram
10:$269.5 per gram
11:$683.6 per gram
12:$33.65 per tablet
13:$24 Billion
</blockquote>
Arnav Joy comments:
you want both the things?
then try this
$custom_value = get_post_meta(6918 , $value , true);
echo "<li><span class='post-meta-key'>$value :</span>".$custom_value."</li>\n";
vitaminman comments:
Awesome. Thank you.
Luis Abarca answers:
You can get all custom fields with [[LINK href="http://codex.wordpress.org/Function_Reference/get_post_custom"]]get_post_custom[[/LINK]]
Change
<span>THIS IS WHERE I NEED HELP!!!!!! <?php $meta = get_post_meta( get_the_ID(6918 ALL CUSTOM FIELDS) ); ?></span>
To
<span><?php $meta = get_post_custom( 6918 ); ?></span>
<?php
foreach ( $meta as $key => $value ) {
echo $key . " => " . $value . "<br />";
}
?>
vitaminman comments:
Hi,
Thank you for sending that php. However, it is still not working. I inserted the php code, so this is what I have now.
function japan_numbers() {
if (is_tag('japan')) {global $wpdb;
?>
<ul class="value">
<li><span><strong>** Click to view value source</strong></span></li></ul>
<ol class="total">
<li>Japan Black Market Value <span><?php echo get_post_meta(6918,'Total Country Black Market Value',true); ?></span></li>
</ol>
<h2 class="related_links">Country Values</h2>
<ul class="country_info">
<span><?php $meta = get_post_custom( 6918 ); ?></span>
<?php
foreach ( $meta as $key => $value ) {
echo $key . " => " . $value . "<br />";
}
?>
</span>
}
?>
</ul>
<?php
}}
add_action('thesis_hook_feature_box', 'japan_numbers');
This is what it displays:
Country Values
Video Game Piracy => Array
_wp_page_template => Array
_edit_lock => Array
_edit_last => Array
Total Country Black Market Value => Array
Counterfeit Goods => Array
Drug Trafficking => Array
Movie Piracy => Array
Software Piracy => Array
Marijuana Price => Array
Cocaine Price => Array
Heroin Price => Array
Ecstasy Price => Array
Prostitution => Array
} ?>
Any suggestions?
Luis Abarca comments:
do you need just "Total Country Black Market Value" values isn't ??
function japan_numbers()
{
if (is_tag('japan')) {
global $wpdb;
?>
<ul class="value">
<li><span>** Click to view value source</span></li>
</ul>
<ol class="total">
<li>Japan Black Market Value <span><?php echo get_post_meta(6918,'Total Country Black Market Value',true); ?></span></li>
</ol>
<h2 class="related_links">Country Values</h2>
<ul class="country_info">
<span>
<?php
$meta = get_post_custom( 6918 );
// just values from market value
$data = $meta['Total Country Black Market Value'];
foreach ( $data as $key => $value ) {
echo $key . " => " . $value . "<br />";
}
?>
</span>
</ul>
<?php } // endif
}
add_action('thesis_hook_feature_box', 'japan_numbers');
vitaminman comments:
No, each individual custom field has its own value. So for some, the name of the custom field is "Counterfeit Goods", and the value is "$300 Million". Then next custom field name is Illegal Logging, and the value is $100. and so on. So in the first code you sent me, the php was catching the Custom Name, but not the value.