2012-06-24 00:30


Alright, I have created a custom meta box on the post edit screens for my custom post type. What I'd like to be able to do with it is allow the user to input a link and then have a button where the post is displayed to take the user to the specified link. What hook would I use to call the meta boxes data?



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanci3845 duanci3845 9年前

    I am not sure that I understand the question, but :

    1 - to display custom meta data you do not need a hook, but a function.

    it is called is get_post_meta() (click the link to learn more.)

    2 - If you want to create a link , usually what is done is to have 2 meta fields, One for the URL itself and one for the URL Display text ( or your button) .

    Then you cann do , for example :

    $my_URL = get_post_meta($post_id, $my_URL, true); ?>
    $my_URL_mask = get_post_meta($post_id, $my_URL_mask, true); ?>

    And then

     <a href="<? echo $my_URL; ?>" rel="whatever" title = "go to <?echo $my_URL;?>" alt="<?php echo $my_URL; ?>" /> <? echo $my_URL_mask ?> </a>

    Now , if your custom fields values will be for example :

    $my_URL = 'CLICK HERE';
    $my_URL = 'http://codex.wordpress.org/Function_Reference/get_post_meta';

    That will create you a link text link that will be like the one above .

    If you do not want the url mask, and only the URL to display as text - then just use one value .

    3 - If you want it to show in a BUTTON , that is a nother story, and it is CSS related - it will depend how you want your button to look, and in that case - you just put those values inside the markup.

    点赞 评论 复制链接分享