Custom field template

Hi, I was wondering if there is an admin template for the custom post with its fields I have created.

I would like to add the “SLT file select” media library button behind the custom text field. This textfield value is the url of an image.

Hope you can help me.

Greets Jair

  • Philip John
    • DEV MAN’s Apprentice

    Hiya!

    If I understand correctly you’d like a custom field you’ve created to use the WordPress media library?

    You would need to custom develop such a feature as custom fields are fairly basic. Have you considered using the featured image functionality instead?

    Phil

  • portfoliooo
    • New Recruit

    Hi Phil,

    What can the feature image do?

    Actualy I have got a custom text field (_ct_text_4e08fe67a3405). My custom post type is called “info” and have placed the following code in single-info.php:

    <?php

    $profile_photo = get_post_meta($post->ID, ‘_ct_text_4e08fe67a3405’, true);

    if ($profile_photo == ”:wink:

    {?>

    <?php }

    else { ?>

    <img src=”<?php echo get_post_meta($post->ID, “_ct_text_4e08fe67a3405″, true);?>” width=”165px” align=”left” style=”margin-right: 6px;”/>

    <?php }?>

    It is working great, but the user need to fill in the url of the image in the custom field. So he/she needs to go to the library, find the url, copy it and needs to go back to the post :slight_frown:

    The best thing to do is to show a button behind the custom field that opens the library and inserts the url of an image directly in the field.

    Have you got any idea how to solve this?

    Maybe to place some code in the post type template in the backend??? Only I do not know where it is. I can only see the post.php in the admin folder. But not something like post-info.php.

    Thanks for your quick respond :slight_smile:

  • portfoliooo
    • New Recruit

    Okay, great! That comes in very handy.

    I will continue with this.

    But for the future … what if I have got more fields I want to place images? This solution is only for one image, not?

    And do you know where the post type admin template is? That way I can customize the edit page and reorder the fields.

  • Philip John
    • DEV MAN’s Apprentice

    Yep that would only do one image.

    If you wanted more you would need to paste in the URL to the image into a custom field.

    To do it any other way (such as providing a file upload) you would need to develop a custom plugin that hooks into the add new page for your custom type and provide that functionality.

    Phil

  • portfoliooo
    • New Recruit

    Okay, I understand.

    My last question. If this is possible, all my problems are solved :slight_smile:

    Is it possible to insert the value of a custom field from another post into a page???

    Maybe with shortcodes or something else?

    How can this be done?

    I realy hope you have got a solution for this.

    Greets jair

  • portfoliooo
    • New Recruit

    Never mind. I have got it. Named a new template page, because I want to make default info pages with the custom field values of one post. That way, the user only needs to fill the custom fields in one post. Like contact fields, bio fields and portfolio fields. And 3 pages are automaticaly being created named contact.php, bio.php and portfolio.php

    An example of triggering the field value into a page is written below.

    Under <? php the_content(); ?> I typed in:

    <?php

    $my_id = 365;

    $field_post = get_post($my_id);

    $field_value = get_post_meta( $field_post->ID, ‘_ct_text_4e04cf658aa81’, $single = true);

    if ( $field_value != ” )

    {?>

    <?php echo $field_value; ?>

    <?php }

    else { ?>

    <?php }?>

    :slight_smile: Hope people can understand this

  • portfoliooo
    • New Recruit

    The only thing you need to do is to design your edit page of that particular post with all the custom fields. Like creating 3 boxes (contact, bio and portfolio) and reordering the fields.

    Would not that be great!

    Only I do not know how to do that! :slight_frown:

    Where can I find/create the edit-post template in the admin???

    Phil, any ideas?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.