[resolved] URL from a custom field to get_meta_tags function (6 posts)

  1. astair
    Posted 7 years ago #

    I'm working on a showcase site with ratings. I'd like to add a description of each site automatically. This can be done with get_meta_tags() function. And as far as I know, I'm not able to use PHP in custom fields(?)

    It's easy when there's only one certain website to fetch the description from:

    <?php $tags = get_meta_tags('http://www.example.com/');
    echo $tags['description']; ?>

    But in this case I want to fetch them automatically from each site and the function is placed within my single.php file.

    I've got a custom field named URL with a website url as value (I use it for other purposes too). So, I would like to have the get_meta_tags function grab the website's url from the custom field.

    I'm a rookie with anything concerning PHP but I've tried several ways to achieve my goal. I've read a few tutorials and manuals but each of them have examples only of fetching the tags from one specific url.

    Is there a way to run some function inside the get_meta_tags() function or do I need to go even further somehow?

  2. MichaelH
    Posted 7 years ago #

    Might want to review Using_Custom_Fields and then go from there...

  3. astair
    Posted 7 years ago #

    Thanks MichaelH but I have tried to figure it out there as well. The problem is that I don't seem to find a way to make the get_meta_tags function to read from i.e. WP's get_post_meta($post->ID, $url, $single = true) so that it would know where to fetch the description from. I keep getting an error saying:

    get_meta_tags(get_post_meta($post->ID, $url, $single = true)) [function.get-meta-tags]: failed to open stream: No such file or directory in **path to my single.php**

    where get_post_meta($post->ID, $url, $single = true) is whatever I've put inside the get_meta_tags function. As I said, I'm a rookie with PHP, so maybe someone could tell me how to create a valid function inside the get_meta_tags function.

  4. Mark / t31os

    Posted 7 years ago #

    Based on the above..

    <?php $tagurl = get_post_meta($post->ID, YOURCUSTOMFIELDNAME, true);
    if($tagurl) : $tags = get_meta_tags( $tagurl ); echo $tags['description'];
    else : echo 'no tag url';

    *I think* :)

  5. astair
    Posted 7 years ago #

    Absolutely beautiful! Thank you t31os_.

  6. t31os
    Posted 7 years ago #

    No problem.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic