dtvpl739577 2014-07-25 14:56
浏览 31
已采纳

向Wordpress菜单项显示自定义发布元数据

this is my first post so first of all : hello everybody, glad to be a part of the community. Secondly please escuse-me in advance for all the English mistakes, i'm french ...

Now this is the problem i have with Wordpress as i'm not a good developer for now :

I've created a custom post type based on the page model named 'Projects' for a more friendly display in the admin :

add_action( 'init', 'create_post_type' );

function create_post_type() {
    register_post_type( 'Projects', array(
        'labels' => array(
            'name' => __( 'Menu Projects' ),
            'singular_name' => __( 'Project' )
        ),
        'hierarchical' => true,
        'capability_type' => 'page',
        'supports' => array('title','editor','thumbnail','custom-fields'),
        'public' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-art'
    ));
}

Then i've add some custom fields i need :

add_action('wp_insert_post', 'wpc_champs_personnalises_defaut');

function wpc_champs_personnalises_defaut($post_id){
if( $_GET['post_type'] = 'Projects' ){
    add_post_meta(1, 'company', '', true);
    add_post_meta(2, 'année', '', true);
}
return true;
};

And now what I want is to display those post meta values in my menu items , right next to the name of the page !

I've tried different things unsucessfully, so if a Wordpress master could help me, that would be great ! Thanks in advance , have a good day !

  • 写回答

2条回答 默认 最新

  • duanduan1993 2014-07-25 15:07
    关注

    When you add the post meta, you should supply the $post_id as the first argument.

    add_post_meta( $post_id, 'company', 'value here' );
    

    and when you want to the post meta you can use get_post_meta function

    get_post_meta( $post_id, 'company', true );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题