Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

What i'm getting wrong in this do_shortcode (VSW plugin) WordPress

  • SOLVED

Hi everyone,

I'm trying to get a video to be displayed by getting values from custom fields and running a shortcode for VSW outside the loop.

My code is :


<?php
$serviceextraitdoc = get_post_meta(get_the_ID(), 'ecpt_service_extrait_doc', true);
$idextraitdoc = get_post_meta(get_the_ID(), 'ecpt_id_extrait_doc', true);
echo do_shortcode('[vsw id="'.$idextraitdoc.'" source="'.$serviceextraitdoc.'" width="460" height="259" autoplay="no"]'); ?>


If i replace '.$serviceextraitdoc.' by the actual value (vimeo) it does work, print_r ($serviceextraitdoc) echoes the right value (vimeo), yet the above lines don't work and i get a blank area with no value for the source+id URL.
As may be seen here http://lafabriquedureel.fr/tds/docs/philippe-petain/

Not being a PHP pro, would be grateful for the solution...

Cheers

Answers (4)

2011-12-16

Hai Bui answers:

Best way to debug this is printing the whole shortcode string:
echo '[vsw id="'.$idextraitdoc.'" source="'.$serviceextraitdoc.'" width="460" height="259" autoplay="no"]';
and see if it's correct or not.


annabelR comments:

Hi Hai Bui,

It returns : [vsw id="17441396" source=" vimeo" width="460" height="259" autoplay="no"]

Which is the correct shortcode ...

Mystery getting thicker.


Hai Bui comments:

you see, there is a space before 'vimeo'
source=" vimeo"

I think this is the problem. I don't know why that space come from but this code may solve the problem:

<?php
$serviceextraitdoc = trim(get_post_meta(get_the_ID(), 'ecpt_service_extrait_doc', true));
$idextraitdoc = trim(get_post_meta(get_the_ID(), 'ecpt_id_extrait_doc', true));
echo do_shortcode('[vsw id="'.$idextraitdoc.'" source="'.$serviceextraitdoc.'" width="460" height="259" autoplay="no"]'); ?>


annabelR comments:

Thx Hai Bui!

Actually the extra blank space was coming from the custom field itself.
Fixed it : working!

2011-12-16

Ivaylo Draganov answers:

Hello,

if outside the loop, you should access the global $post variable, get_the_ID() doesn't work:

<?php
global $post;

$serviceextraitdoc = get_post_meta($post->ID, 'ecpt_service_extrait_doc', true);
$idextraitdoc = get_post_meta($post->ID, 'ecpt_id_extrait_doc', true);
echo do_shortcode('[vsw id="'.$idextraitdoc.'" source="'.$serviceextraitdoc.'" width="460" height="259" autoplay="no"]');
?>


annabelR comments:

Hi Ivaylo,

Actually the get_the_ID() does work...
Not the problem, i'm afraid.

2011-12-16

Arnav Joy answers:

what is the value of $serviceextraitdoc ,did you print it.

echo $serviceextraitdoc;


annabelR comments:

Hey Robin,

I did. Returns the right value (ie. vimeo).
When i replace the '.$serviceextraitdoc.' by the string (vimeo) it does work ?!!

: - (


Arnav Joy comments:

please deactivate all other plugins for once and then try your code.

2011-12-16

Francisco Javier Carazo Gil answers:

Ivaylo,

You have a typing error: $idextraitdoc = get_post_meta($post->ID, 'ecpt_id_extrait_doc', true);

Nothing important.

Annabel, is this ok?


Francisco Javier Carazo Gil comments:

Hi Annabel,

If what Ivaylo have said is not the problem, try the next:
1. Look at the value of $serviceextraitdoc: <?php echo "<!-- $serviceextraitdoc -->";?> into an HTML comment to prevent showing, let you can see it from the source code.
2. If all is OK, try to set WP_DEBUG to true and tell me if there are any problem: define('WP_DEBUG', true);

Regards.


annabelR comments:

Hey Francisco,
No typing error ecpt_id_extrait_doc is the id of the custom field i'm getting the value of...
print_r (instead of echo) returns the right value... So i really don't get it...
:- (

I'll try debug mode and will let you know
Cheers,


Francisco Javier Carazo Gil comments:

PHP is a non typed language. So maybe this is the problem.

Try to do a explicit casting:

$serviceextraitdoc = (string)$serviceextraitdoc