0

Here's what I'd like to do. This function which grabs the content of a custom Wordpress post field:

get_post_meta($post->ID, 'society_twitter', true);

Needs to run in place of the string 'yourTwitterUsername' below,

[twitter-widget username="yourTwitterUsername"]

Looking something like:

[twitter-widget username="get_post_meta($post->ID, 'society_twitter', true);"]

Is this possible? If so, what is the syntax? A little more detail: I'm trying to modify a Twitter widget to display the username listed in a custom post field in my database rather than just one string value. I've tried editing the plugin php itself but this seems like an easier solution.

1 Answer 1

3

Use string concatenation?

$string = '[twitter-widget username="' . get_post_meta($post->ID, 'society_twitter', true) . '"]';

Edit: Updated based on the comments:

$string = '[twitter-widget username="' . get_post_meta($post->ID, 'society_twitter', true) . '"]';
echo do_shortcode( $string);
Sign up to request clarification or add additional context in comments.

5 Comments

It depends on how you're generating [twitter-widget username="yourTwitterUsername"].
echo do_shortcode('[twitter-widget username="yourTwitterUsername"]');
So it'd look like echo do_shortcode($string = '[twitter-widget username="' . get_post_meta($post->ID, 'society_twitter', true) . '"]'); ?
Yes, I updated my answer to put it to two lines, but yes, except without the $string = in your code.
Brilliant, works like a charm. Will mark as answered ASAP. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.