Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin where the user can click a button to feature a post.

I added a text field but i want the text field to call back whatever is posted in it

Here is how it looks now

http://ratedrnb.com/wp-content/uploads/2013/05/ffm2.jpg

now the plugin grabs the thumbnail of the post but i also want it to grab whatever is in the "Artist/Song" field.

Here is the code where the "Featured Music Options" is

<?php
/*
Plugin Name: Featured Music
Plugin URI: LittleLadyEnterprises.com
Description: This Plugin is used to show your featured Posts/Pages with thumbnails in a nice slider.
Version: 2.6
Author: Little Lady Enterprises
*/

  $m_slider_options_page = get_option('siteurl') . '/wp-admin/admin.php?page=rated-featured-music/options.php';

 function m_slider_options_page() {

add_options_page('Featured Music Options', 'Featured Music', 10, 'rated-featured-music/options.php');

 }

 add_action('admin_menu', 'm_slider_options_page');

 function m_slider_add_scripts() {

    if ( !is_admin() ) {

            wp_register_script('jquery.cycle', get_bloginfo('url') . '/wp-content/plugins/rated-featured-music/scripts/jquery.cycle.all.2.72.js', array('jquery'), '1.3' );
            wp_enqueue_script('jquery.cycle');

     }

 }

 add_action('wp_enqueue_scripts', 'm_slider_add_scripts');


 function m_slider_cut_text($text, $chars, $points = "...") {

$content = $text;

$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content); 
$content = str_replace(']]>', ']]&gt;', $content);
$content = strip_tags($content);

$length = strlen($content);

if($length <= $chars) {

    return $content;

 } else {

    return mb_substr($content, 0, $chars)." ".$points;

}
}

add_action("admin_init", "m_slider_init");
add_action('save_post', 'm_slider_save');

function m_slider_init() {

    add_meta_box("feat_music", "Featured Music Options", "m_slider_meta", "post", "normal", "high");
    add_meta_box("feat_music", "Featured Music Options", "m_slider_meta", "page", "normal", "high");

}

function m_slider_meta() {

    global $post;
    $custom = get_post_custom($post->ID);
    $feat_music = $custom["feat_music"][0];

?>

        <div class="inside">
    <table class="form-table">
        <tr>
            <th><label for="feat_music">Feature in Featured Music?    </label></th>
            <td><input type="checkbox" name="feat_music" value="1" <?php if($feat_music == 1) { echo "checked='checked'";} ?></td>

<th><label for="points">Artist/Song</label></th>
                <td><input type="text" name="artist_title" value="Artist - Song"></td>
        </tr>
    </table>
</div>

<?php

}

 function m_slider_save() {

    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    return $post_id;
    global $post;

    if($post->post_type == "post" || $post->post_type == "page") {

            update_post_meta($post->ID, "feat_music", $_POST["feat_music"]);

    }

}

function m_slider_insert($atts, $content = null) {

    include (ABSPATH . '/wp-content/plugins/rated-featured-music/content-slider.php');

}

add_shortcode("featslider", "m_slider_insert");

$m_slider_img_width = get_option('img_width');

if(empty($m_slider_img_width)) {

    $m_slider_img_width = 320;

}

$m_slider_img_height = get_option('img_height');

if(empty($m_slider_img_height)) {

    $m_slider_img_height = 200;

}

if (function_exists('add_image_size')) {

add_image_size( 'feat_music', $m_slider_img_width, $m_slider_img_height, true );

}

function m_slider_get_thumb($position) {

$thumb = get_the_post_thumbnail($post_id, $position);
$thumb = explode("\"", $thumb);
return $thumb[5];

}

//Check for Post Thumbnail Support

add_theme_support( 'post-thumbnails' );

function m_slider_get_dynamic_class() {

    $class = explode("http://", get_bloginfo("url"));
$class = explode(".", $class[1]);
    $class = $class[0];
    return $class . "_slider";

}

?>

What is the callback code that I need to add to the Value Area?

The code below is the styling of the plugin and callback codes, what is the callback code to call back whatever is placed in the textarea.

<?php

$m_slider_direct_path =  get_bloginfo('wpurl')."/wp-content/plugins/rated-featured-music";

$m_slider_class = m_slider_get_dynamic_class();

?>

<div id="featuredmusicbox">
<?php

    $m_slider_sort = get_option('sort'); if(empty($c_slider_sort))    {$c_slider_sort = "post_date";}
    $m_slider_order = get_option('order'); if(empty($c_slider_order)){$c_slider_order = "DESC";}
    $m_slider_post_limit = get_option('limit_posts');     if(empty($m_slider_limit_posts)){$m_slider_limit_posts = "-1";}

    global $wpdb;

    global $post;

    $args = array( 'meta_key' => 'feat_music', 'meta_value'=> '1', 'suppress_filters' => 0, 'post_type' => array('post', 'page'), 'orderby' => $m_slider_sort, 'order' => $m_slider_order, 'numberposts'=> $m_slider_post_limit);

    $myposts = get_posts( $args );

    foreach( $myposts as $post ) :  setup_postdata($post);

        $m_slider_custom = get_post_custom($post->ID);

        $m_slider_thumb = m_slider_get_thumb("featmusic");

    ?>


            <div class="image"><a href="<?php the_permalink();?>"><?php the_post_thumbnail('featmusic'); ?></a></div>
 <div id="titlelisten">
 <div class="titlefm"><center><a href="<?php the_permalink();?>">TEXT AREA TEXT HERE</a></center></div> <div class="listenfm"><a href="<?php the_permalink();?>"><img src="http://ratedrnb.com/wp-content/uploads/2013/05/listen.jpg"></a></div>
</div>
</div>
<?php endforeach; ?>    
share|improve this question
add comment

1 Answer

Your text is already in the array $m_slider_custom, from this line:

$m_slider_custom = get_post_custom($post->ID);

If you just want the specific key feat_music you can use get_post_meta():

echo get_post_meta( $post->ID, 'feat_music', true );

Another, unrelated thing- I suggest spending some time with the Codex and cleaning up your URLs and paths. For example, this:

get_option('siteurl') . '/wp-admin/admin.php?page=rated-featured-music/options.php';

or this:

get_bloginfo('url') . '/wp-content/plugins/rated-featured-music/scripts/jquery.cycle.all.2.72.js'

or this:

include (ABSPATH . '/wp-content/plugins/rated-featured-music/content-slider.php');

.. will fail spectacularly under certain circumstances. WordPress has built in functions for getting any path or URL you'd need, see:

http://codex.wordpress.org/Function_Reference/admin_url http://codex.wordpress.org/Function_Reference/plugins_url http://codex.wordpress.org/Function_Reference/plugin_dir_path

share|improve this answer
    
I don't get what you are saying lol or maybe you aren't understanding what I mean @Milo –  user32447 May 31 '13 at 1:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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