dpn517111 2014-02-20 13:55
浏览 36
已采纳

Wordpress自定义元框复选框,在首页上显示文本

I'm creating a video site in wordpress that will feauture both videoes and live streaming. The live streaming is occational and I'm trying to add a checkbox in the "new post" section where the user can check the box to display an alert that they are streaming live on the front page.

This is my code so far, but it does not save that the chebox is checked.

function register_post_assets(){
    add_meta_box('live-tv', __('Live TV'), 'add_featured_meta_box', 'post', 'advanced', 'high');
}

add_action('admin_init', 'register_post_assets', 1);

function add_featured_meta_box($post){
    $featured = get_post_meta($post->ID, 'live-tv', true);
    echo "<label for='live-tv'>".__('Is this a live broadcast post?', 'foobar')."</label>";
    echo "<input type='checkbox' name='live-tv' id='live-tv' value='1' ".checked(1,         $featured)."     />";
}

function save_featured_meta($post_id){
if (isset($_REQUEST['live-tv']))
    update_post_meta(esc_attr($post_id, '_featured-post', esc_attr($_REQUEST['featured-post']))); 
}
add_action('save_post', 'save_featured_meta');

I'm also wondering how i can check if the checkbox is checked to display content on the front page. Thank you so much for your time and any help will be appreciated!

  • 写回答

1条回答 默认 最新

  • doxrxwn2252 2014-02-20 14:01
    关注

    You have an error in your save_featured_meta function:

    It has to be like this:

    function save_featured_meta($post_id)
    {
        if (isset($_REQUEST['live-tv']))
            update_post_meta(esc_attr($post_id), '_featured-post', esc_attr($_REQUEST['featured-post']));
    }
    

    You didn't close the esc_attr() at the right place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题