I need to use a plugin shortcode within a template file, but have one of the variables be set by the value of a custom field in the post. Here's what I have so far. This just breaks the entire page.
My effort (not working):
<?php echo do_shortcode('[wpsp pls_id="get_post_meta($post->ID, 'playlist', true)"]'); ?>
The shortcode:
[wpsp pls_id="NEED VALUE SET HERE"]
The custom field function:
<?php echo get_post_meta($post->ID, 'playlist', true); ?>
Thanks.
Try this:
<?php echo do_shortcode('[wpsp pls_id="' . get_post_meta($post->ID, 'playlist', true) . '"]'); ?>
Related
I'm using Coupon Creator and I like that it comes with the categories and shortcodes. I am using a category shortcode like this example [coupon couponid="loop" category="Brumby's Bakery" couponorderby="date" coupon_align="cctor_alignnone" name="Coupon Loop"].
I wanted to use different category shortcode for each page. Therefore, I kinda created a custom meta box for that (Wordpress Meta Boxes) and called it in the php template page with <?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>. However, the shortcode won't work in php template page unless I use <?php echo do_shortcode('[coupon...]'); ?>
In the end this code which was supposed to be like that wouldn't work because of php in php.
<?php echo do_shortcode(<?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>); ?>
How do I rework this php code? The only thing I could think of is to use something like var but I don't know how to make it work in php template page.
var $store = <?php echo get_post_meta($post->ID, 'couponshortcode', true); ?>
<?php echo do_shortcode($store); ?>
No need to echo get_post_meta(). This should work:
<?php echo do_shortcode(get_post_meta($post->ID, 'couponshortcode', true)); ?>
I'm displaying a gallery on my wordpress site using the following code:
<?php echo do_shortcode('[satellite gallery=2 auto=off caption=off thumbs=on]'); ?>
Now I've added a custom post value/field called 'guitLink' where I can add the gallery number which I want to then use in the above shortcode, so something like this:
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). 'auto=off caption=off thumbs=on]'); ?>
Any ideas how to achieve this?
Use:
<?php $guitLink = get_post_custom_values('guitLink');
echo do_shortcode('[satellite gallery=' .$guitLink[0]. ' auto=off caption=off thumbs=on]'); ?>
Instead of
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). ' auto=off caption=off thumbs=on]'); ?>
Im trying to use do_shortcode to display data from an advanced custom field which is in the admin cms.
I have an advanced customed field called 'meta_slider_shortcode'. I would like the do_shortcode to display the data that is in the meta_slider_shortcode' field.
Here is my php:
<?php
$meta = get_field( "meta_slider_shortcode" );
echo do_shortcode('$meta');
?>
Check the value of $meta. If it does not contain square brackets then add it in do_shortcode like do_shortcode("[$meta]");
The short code cant have ' ' wrapped around the variable.
Here is a working example:
<?php
$meta = get_field( "meta_slider_shortcode" );
echo do_shortcode($meta);
?>
if you have short code then use it some thing like this
$yourvar = do_shortcode( '[your-short-code]' );
echo $yourvar;
or
echo do_shortcode( '[your-short-code]' );
in your case it would
echo do_shortcode(get_field( "meta_slider_shortcode" ));
this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>
How do I echo a Wordpress plug in short code that I will be putting in the Custom Meta field in the post I have called Treatment 1?
Short code is
[table id=6 /]
My php which I cant work is
<?php
$post_meta = get_post_meta($post->ID, "Treatment Right 1", true);
if (!empty($post_meta)) {
?>
<?php echo do_shortcode($post_meta;); ?>
<?php
}
?>
Please help
<?php echo do_shortcode($post_meta); ?>
You have a semi colon inside your shortcode function for a start.
not 100% sure what you are trying to achieve.
Does the custom meta field just contain the name of the shortcode or the full string?
i.e. does it include the square brackets [shortcode] rather than just returning 'shortcode'
you could try:
echo do_shortcode('['.$post_meta.']');
have you written the shortcode function of 'table' yourself?