• I’m trying to use this code to display, well the values. However, it doesn’t return anything, even when there is a value in the custom data fiels of the post.

    <a href="<?php get_post_custom_values($wp_source_href) ?>" target="blank"><?php get_post_custom_values($wp_source_name) ?></a>

    Any suggestions as to why i don’t get a result?

    A preview link is here: http://www.marzar00.finditmax.com/index.php/archives/96

    It should display this:
    <a href="http://www.google.com.au" target="blank">Google Australia</a>

Viewing 15 replies - 1 through 15 (of 16 total)
  • $wp_source_href and $wp_source_name–what are those initialized to?

    Thread Starter marzar00

    (@marzar00)

    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?

    Thread Starter marzar00

    (@marzar00)

    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!

    Thread Starter marzar00

    (@marzar00)

    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>

    Thread Starter marzar00

    (@marzar00)

    Does anyone know how to get this working properly?

    Thread Starter marzar00

    (@marzar00)

    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;
    }
    ?>

    Thread Starter marzar00

    (@marzar00)

    Ah ok thats alphaoide and Kafkaesqui, I will test both of those and hopefully one will work.

    Just a sec

    Thread Starter marzar00

    (@marzar00)

    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.

    Thread Starter marzar00

    (@marzar00)

    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.

    Thread Starter marzar00

    (@marzar00)

    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; ?>

Viewing 15 replies - 1 through 15 (of 16 total)

The topic ‘Custom Field Data Intergration’ is closed to new replies.