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条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗