1

Ok I suck at PHP, so I'll explain this in "English" first then proceed to code.

I've got a custom field in my WP DB called ecpt_imdb - this is the numeric value of a movie from the imdB. For example: http://www.imdb.com/title/tt0848228/

My ecpt_imdb value would be: tt0848228

I then purchased a widget that parses a URL when entered into my WP editor. It works fine, but I've got few thousand movie reviews and to manually enter their imdB string in each review would take far more time than I want to devote to this.

So...I got thinking that If I could use the value from the ecpt_imdb that's already a part of each review, I could just have a chunk of code that says "If ecpt_imdb exists then attach that to the end of the line of code and it'll spit out what I want it to."

Essentially here's what I have that's not working, feel free to amend it and I'll try to see what works.

The code author gave me a few lines, but I don't think he knows what I'm trying to do:

This works (in single.php) but it's hard-coded. I want a dynamic version of this below:

    <?php echo do_shortcode( '[imdb]http://www.imdb.com/title/tt2724064/[/imdb]' ); ?>

Here's what I have. It does not work.

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    if( get_post_meta($postid, 'imdb_rating', true)) { ?>

    <?php }
    elseif( get_post_meta($postid, 'ecpt_imdb', true)) {
    ?>
    <h3>About the Movie</h3>
    <?php echo do_shortcode( '[imdb]http://www.imdb.com/title/' . $ecpt_imdb . '/[/imdb]' ); ?>
    <?php } ?>

1 Answer 1

0

Nice one, you were practically there - the key is to assign the $ecpt_imdb variable with the data returned from get_post_meta:

<?php if ( $ecpt_imdb = get_post_meta( get_the_ID(), 'ecpt_imdb', true ) ) : ?>

    <h3>About the Movie</h3>
    <?php echo do_shortcode( '[imdb]http://www.imdb.com/title/' . $ecpt_imdb . '/[/imdb]' ) ?>

<?php endif ?>

You'll see I've also used the template tag get_the_ID(), which is the "correct" way of getting the current post ID.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.