• Resolved arifbd111

    (@arifbd111)


    Hi
    I am trying to update Single.php page and retrieve data from Custom Field variable. My target is to retrieve a URL link from custom field and create a link through URL Link. For retrieving custom field data and crate a Link I’ve write this code in Single.php file

    $str = get_post_meta($id, "website", true);
    
    echo ""?> <a href="<;?php echo $str; ?>" target="blank">Example.com</a>

    For Example, if the the custom field data retrieve http://www.example.com, here in my code the link shows my local servers link (I am testing on my local server) http://localhost/mysite/2011/09/07/test1/www.example.com

    So, here actually the Example.com is tagged with a wrong URL where I want it to only show http://www.example.com
    How to solve this URL Problem? 🙁

Viewing 2 replies - 1 through 2 (of 2 total)
  • Phil

    (@owendevelopment)

    Try something like this:

    For this example, let’s say the name of your custom field is ‘link_url‘.

    <?php if ( get_post_meta($post->ID, 'link_url', true) ) { ?>
    <a class="someclass" href="<?php echo get_post_meta($post->ID, link_url, true); ?>"><?php echo get_post_meta($post->ID, link_url, true); ?></a>
    <?php } ?>
    
    <?php if ( get_post_meta($post->ID, 'link_url', false) ) { ?>
    <?php } ?>

    So in your custom field, you could add http://www.example.com and it will pull the link to where you insert this on the site.

    I have used this on a couple of sites to pass links and it works well.

    Thread Starter arifbd111

    (@arifbd111)

    Thanks PSM Digital!

    I’ve also just solved it i think. I am not a PHP expert :p. What I did is just update the custom field data from http://www.example.com to http://www.example.com and it worked nice. 🙂 I think http:// is the key here.

    Thanks again to PSM Digital for your answer 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘URL problem in Single.php when retrieve data from Custom Field’ is closed to new replies.