WordPress.org

Ready to get started?Download WordPress

Forums

Getting getCustomField() function to Return instead of Echo (19 posts)

  1. newyorkcity
    Member
    Posted 2 years ago #

    I'm trying to get a url to display inside the "Peek" link in my RSS but its displaying at the top before its suppose to. Here is a screenshot: http://cl.ly/image/0k1o2k251q0P

    Where it says "http://testinglink.com" is suppose to be in the href="..." for the Peek link at the bottom.. but its displaying in the Google RSS Reader too soon.

    And here is the function in Pastebin: http://pastebin.com/1jBhNS1n

    How do I fix this?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    getCustomField() is not a WordPress function (plugin?). Can we have a look at that function?

  3. newyorkcity
    Member
    Posted 2 years ago #

    I'm not sure where to find that.. I'm using this plugin: http://wordpress.org/extend/plugins/custom-field-template/ for the custom fields on the website

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    I couldn't find the function in the plugin. do you have this in your theme's functions.php:
    http://wordpress.org/support/topic/plugin-custom-field-template-insert-custom-code-into-a-template?replies=9

  5. newyorkcity
    Member
    Posted 2 years ago #

    nope! dont have that in there anywhere

  6. newyorkcity
    Member
    Posted 2 years ago #

    should that be added or should the code be altered to do what im trying to do?

  7. keesiemeijer
    moderator
    Posted 2 years ago #

    should that be added or should the code be altered to do what im trying to do?

    No, the function not WordPress and not from the plugin so I think it has to be from another plugin or somewhere else in your theme.

  8. newyorkcity
    Member
    Posted 2 years ago #

    so something else is causing getCustomField() to echo?

  9. keesiemeijer
    moderator
    Posted 2 years ago #

    Search your theme template files for "getCustomField"

  10. newyorkcity
    Member
    Posted 2 years ago #

    Ok, copying all the theme files to my computer from ftp so i can search them all give me a sec

  11. newyorkcity
    Member
    Posted 2 years ago #

    I don't see it defined anywhere, all I see is <?php getCustomField('Affiliate Link'); ?> and other types of fields for example: <?php getCustomField('Pricing'); ?> in the template files and i showed you what was in the themes functions.php file.. I also tried the custom-field-template plugin folder and nothing showed up for getCustomField. Would this mean its just echoing by default and its not defined?

  12. Andrew
    Forum Moderator
    Posted 2 years ago #

    In this function
    http://pastebin.com/1jBhNS1n
    It isn't echoing out anything, so where are you using the returned value to echo it out?

  13. newyorkcity
    Member
    Posted 2 years ago #

    I was told that getCustomField is echoing by default and thats why the url is appearing at the very top like what can be seen here: http://cl.ly/image/0k1o2k251q0P but im not sure how to stop it from appearing at the top and inside href="..." instead

  14. Andrew
    Forum Moderator
    Posted 2 years ago #

    So if you remove getCustomField('Affiliate Link') from the function, in theory the url will cease to appear at the very top.
    Have you tried this?

  15. newyorkcity
    Member
    Posted 2 years ago #

    I havent tried it but how will it work? the 'Affiliate Link' link is where the url is entered: http://cl.ly/image/1T320Y211H46

    To test what you are talking about. do I just remove getCustomField('Affiliate Link') from

    $content = $content . '<a href="' . getCustomField('Affiliate Link') . '">Peek</a>';?

  16. keesiemeijer
    moderator
    Posted 2 years ago #

  17. newyorkcity
    Member
    Posted 2 years ago #

    that works! thank you!

    I do have another quick question, if I wanted to add if{} for the pages that do not have the affiliate link, what would i wrap around $content = $content . '<a href="' . get_post_meta($post->ID, 'Affiliate Link', true) . '">Peek</a>';

    Thanks again!

  18. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with:

    $affiliatelink = get_post_meta($post->ID, 'Affiliate Link', true);
    if($affiliatelink != '') {
      $content .= '<a href="' . $affiliatelink . '">Peek</a>';
    }
  19. newyorkcity
    Member
    Posted 2 years ago #

    Its working thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic