$wp_source_href and $wp_source_name–what are those initialized to?
sorry i don’t understand. That is the defined key in WP that i made, however when ever i view a page with the key in it it returns nothing!!!
You mean $wp_source_href and $wp_source_name are not PHP variables??
If they’re keys, then here’s how you do it.
get_post_custom_values('$wp_source_name')
By the way, why didn’t you name them wp_source_href and wp_source_name?
They are named like that so the i can remember what they are for. wp_source_href is obviously the href of the source and wp_source_name is the name of the source. So basically all i was forgetting was the ‘ . I would forget my head if it wasn’t screwed on!
Ok i added the ‘ ‘ and changed the names, removing the wp_. Here is the new code, which still doesn’t work. Any thoughts?:
<a href="<?php get_post_custom_values('$source_href') ?>" target="blank"><?php get_post_custom_values('$source_name') ?></a>
Does anyone know how to get this working properly?
Ok the tag: <?php the_meta(); ?> returns the desired results but the get_post_custom_values doesn’t seem to be working with 2.0. Any suggestions?
I detest the dollar symbol ($) in the keys, NOT the prefix wp_.
You have to echo it.
echo get_post_custom_values('lovable_key')
Check the database. Are those custom fields stored?
Do you use that piece of code inside the Loop?
Further, get_post_custom_values() sets an array of key->value pairs from your custom field data. So you’d want to do something like the following:
<?php
foreach(get_post_custom_values('lovable_key') as $value) {
echo $value;
}
?>
Ah ok thats alphaoide and Kafkaesqui, I will test both of those and hopefully one will work.
Just a sec
Ok it worked, however i wish to put the source_href as the href in a link tag and the source_name as the link text.
Never mind i got it to work. Here is the code I used:
<?php foreach(get_post_custom_values('source_href') as $source_href) {}
foreach(get_post_custom_values('source_name') as $source_name) {} ?>
<a href="<?php echo $source_href; ?>" target="blank"><?php echo $source_name; ?></a>
Thanks for all the help,
Marzar
You can also try this (a little geeky, so ask if you get lost):
<?php $custom = get_post_custom($post->ID); ?>
<a href="<?php echo $custom['source_href'][0];
?>"><?php echo $custom['source_name'][0]; ?></a>
Modify the key names if necessary to your own.
Ok now I get errors on pages that don’t have the custom fields:
Warning: Invalid argument supplied for foreach() in /home/REMOVED/index.php on line 131
That is from a post without the tags
<?php
if(get_post_custom_values('source_href')) :
foreach(get_post_custom_values('source_href') as $source_href) {}
foreach(get_post_custom_values('source_name') as $source_name) {} ?>
<a href="<?php echo $source_href; ?>" target="blank"><?php echo $source_name; ?></a>
<?php endif; ?>