• Hi,
    So my blog is based on music news and such….

    On my custom fields for embedding media. I only allow 2 sources.
    – Either Youtube OR a SoundCloud URL

    So, i’d like a simple php code that can do this:

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <?php
    Check post meta (get_post_meta($post->ID, 'my_url_media', true);)
    ?>
    <?php if any meta value exist; (continue)
    If post meta contains this string "http://www.youtube";
    echo '
    <div id="JWPlayer"></div>
    <script>
        jwplayer("JWPLayer").setup({
          file: "'.POST META HERE (YOUTUBE).'",
          width: "100%",
          height: 30
        });
    </script>
    ';
    }
    ELSE
    {
    If post meta contains  "http://soundcloud"
    echo '<iframe src=" POST META HERE (soundcloud)" class="somerandomCSSClass"></iframe>'
    ?>

    If there is no meta value, then do nothing at all.

    As you can see, i’m a complete php novice, but at least i know how i’d like the function to work.

    So PHP & WP gurus, what do you think ?

    Thanks for reading

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Hello again!

    You have the right idea, though you’ve a lot to learn about basic syntax 😉 WP has some built in media embedment features you may be able to use, If not directly, then as a model example from those that have gone this way before. You might start by reviewing wp-includes/media.php. Granted, it is mostly for images, but pay attention to the oembed functions, and the relationship to attachments and taxonomies.

    Source code does not make the best reference material for many (works for me though), hopefully others here can point you to some more readable material.

Viewing 1 replies (of 1 total)
  • The topic ‘Check specific "text" from a Custom Field and output it, or else do something..’ is closed to new replies.