• Hi
    i would like a shortcode for another plugin (wordtube) to be recognised in one of my custom fields.
    Is that possible.

    I thought maybe the ‘hook’ option might do this but i couuldn’t find any documentation on that.

    can anyone help?
    thanks
    elvis

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sure you can
    Here’s what you have to do.
    place this in your functions.php file
    <?php

    $new_meta_boxes =
    array
    (
    “contact_wp_info” =>
    array
    (
    “name” => “Video”,
    “std” => “”,
    “title” => “Featured Youtube Video”,
    “description” => “”
    )
    );

    function new_meta_boxes()
    {
    global $post, $new_meta_boxes;
    $wpcm_tab_index = 1000;
    foreach($new_meta_boxes as $meta_box)
    {
    $meta_box_value = get_post_meta($post->ID, $meta_box[‘name’].’_wpcm_value’, true);
    if($meta_box_value == “”)
    $meta_box_value = $meta_box[‘std’];
    echo'<input type=”hidden” name=”‘.$meta_box[‘name’].’_noncename” id=”‘.$meta_box[‘name’].’_noncename” value=”‘.wp_create_nonce( plugin_basename(__FILE__) ).'” />’;
    echo'<p><label style=”letter-spacing:1px; text-transform:uppercase; color:#777;” for=”‘.$meta_box[‘name’].’_wpcm_value”>’.$meta_box[‘title’].'</label>
    ‘;
    echo'<input style=”padding:4px; font-weight:normal; border-top:1px solid #ccc; border-right:1px solid #ddd; border-bottom:1px solid #ddd; border-left:1px solid #ccc;” type=”text” name=”‘.$meta_box[‘name’].’_wpcm_value” value=”‘.$meta_box_value.'” size=”55″ tabindex=”‘.$wpcm_tab_index.'” /></p>’;
    $wpcm_tab_index++;
    }
    }

    function create_meta_box()
    {
    global $theme_name;
    if ( function_exists(‘add_meta_box’) )
    {
    add_meta_box(‘new-meta-boxes’, ‘Media Information’, ‘new_meta_boxes’, ‘post’, ‘normal’, ‘high’);
    }
    }

    function save_postdata( $post_id )
    {
    global $post, $new_meta_boxes;
    foreach($new_meta_boxes as $meta_box)
    {
    // Verify
    if ( !wp_verify_nonce( $_POST[$meta_box[‘name’].’_noncename’], plugin_basename(__FILE__) ))
    {
    return $post_id;
    }
    if ( ‘page’ == $_POST[‘post_type’] )
    {
    if ( !current_user_can( ‘edit_page’, $post_id ))
    return $post_id;
    }
    else
    {
    if ( !current_user_can( ‘edit_post’, $post_id ))
    return $post_id;
    }

    $data = $_POST[$meta_box[‘name’].’_wpcm_value’];

    if(get_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’) == “”)
    add_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’, $data, true);
    elseif($data != get_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’, true))
    update_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’, $data);
    elseif($data == “”)
    delete_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’, get_post_meta($post_id, $meta_box[‘name’].’_wpcm_value’, true));
    }
    }

    add_action(‘admin_menu’, ‘create_meta_box’);
    add_action(‘save_post’, ‘save_postdata’);

    ?>

    Then in your single.php file place the following.
    <div class=”video”>
    <?php $videos = get_post_meta($post->ID, ‘videos_wpcm_value’, true); ?>
    <?php
    $galx = $videos;
    $galx = apply_filters(‘the_content’, $galx );
    echo $galx;
    ?>
    </div>

    Hope this works for you

    Happy coding…

    I forgot to mention about the shortcode, it would be something like this in your custom field.
    [playlist id=1]

    Have fun…

    Nagmay

    (@gabrielmcgovern)

    issy-m,
    Your code rocks and was exactly what I needed for a project. However, I would suggest one update:

    Swap the two elseif statements in save_postdata to be:

    elseif($data == "") delete_post_meta($post_id, $meta_box['name'].'_wpcm_value', get_post_meta($post_id, $meta_box['name'].'_wpcm_value', true));
    elseif($data != get_post_meta($post_id, $meta_box['name'].'_wpcm_value', true)) update_post_meta($post_id, $meta_box['name'].'_wpcm_value', $data);

    Otherwise, it takes saves to delete blank values.
    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Custom Field Template] shortcode’ is closed to new replies.