How can I get custom fields in wordpress?

How can I get Twitter hashtags to pull from a custom field on WordPress?

  • I'm trying to get custom fields to pull up a hashtag I put in inside a tweet button. <a href="https://twitter.com/share" class="twitter-share-button" data-via="artofbackpackin" data-related="artofbackpackin" data-hashtags="<?php echo get_post_meta($post->ID, "tweethashtag", true); ?>">Tweet</a> I've got the custom field filled in but for whatever reason, the hashtag is not displaying on the tweet button. Has anyone tried doing this before?

  • Answer:

    I usually store the data into a variable and call the variable inside the HTTP code. Have you tried the following approach? <?php $selectedHashTag = get_post_meta($post->ID, "tweethashtag", true); ?> <a href="https://twitter.com/share" class="twitter-share-button" data-via="artofbackpackin" data-related="artofbackpackin" data-hashtags="<?php echo $selectedHashTag ?>">Tweet</a> Also, this code must run inside The Loop.

Leonardo Vergani at Quora Visit the source

Was this solution helpful to you?

Other answers

Thanks for the help! I see now. What I did instead was create this: <a href="https://twitter.com/share" class="twitter-share-button" data-via="artofbackpackin" data-related="artofbackpackin" data-hashtags="<?phpglobal $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'tweethashtag', true); wp_reset_query(); ?>">Tweet</a>

Michael Tieso

Hard to say without more code but...the data-{something} is being used by the / to build the tweet. What is data-hashtags? Did you make that up? Or is it a known parm? If you made it up, then the 'script plugin probably doesn't recognize it for what you want. The other possibliblly is related to the length of the string being tweet. Perhaps hashtags is being appended but then being truncated. Maybe?

Mark Simchock

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.