WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
render custom field in theme (25 posts)

  1. mdlepage
    Member
    Posted 2 years ago #

    Hi,

    I'm trying to display the value of a custom text field in my theme's single.php. So here's the code I've added:

    <?php types_render_field("wpcf-price",array('output'=>'html')); ?>

    It just does not work and the field is never displayed.

    Is this the right way to do this or do I have to use the embedded types features? Is there any thing I'm missing here?

    thanks,
    m

    http://wordpress.org/extend/plugins/types/

  2. occupant
    Member
    Posted 2 years ago #

    I have the same issue (and I saw it posted last week as well). According to the API, that's correct. My guess is it's busted.

    Embedding is a poor way to implement this imho - you can't customize the layout as easily or trust others to get it right. I guess it's a way to try to sell Views. I'm sure I could get it to work with Views, but I'm not going to buy a module to 'add' functionality that supposedly exists. I assume Views is similar to Drupal Views (which would make it worth the price).

    It's disappointing - this is sorely needed in WordPress.

  3. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    There are different reasons for the field not to display.

    You added the output to single.php. Does the field belong to a post, or something else? single.php is for posts.

    Did you try to insert that output inside the post body using the Types icon? Does it display there?

    Is the name of the custom field correct?

    Are you getting any PHP errors?

  4. archersify
    Member
    Posted 2 years ago #

    Any solution? I am having the same problem. :(

  5. archersify
    Member
    Posted 2 years ago #

    I found an alternative solution:
    <?php echo do_shortcode('[types field="hotel_full_business_name"]'); ?>

    Put this on your template and it works. :D

  6. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    Folks, you're reporting something wrong, but you're not giving us anything to work on. It's working on our tests.

    Can you provide complete debug information? I asked a set of questions above and I'm not getting any replies to any of them.

  7. Srdjan
    Member
    Plugin Author

    Posted 2 years ago #

    Remove 'wpcf-' prefix from field name. It's prefix for internal usage. We should make that clear in our docs.

    Also echo returned result:
    <?php echo types_render_field("price", array('output'=>'html')); ?>

  8. archersify
    Member
    Posted 2 years ago #

    thanks for the replies.. Now it works. :D

    And i have to agree, this should be made more cleared on the docs. :)

  9. mdlepage
    Member
    Posted 2 years ago #

    @AmirHelzer, @Jozik
    Ok, took a while to get back to you.

    I removed the "wpcf" prefix, added the echo to the php statement and now it works.
    Thanks for the help.
    Updating your documentation with help avoid more posts like this.

    :)

  10. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    I added a note about this in the documentation page. There's no need for each. types_render_field sends to output.

  11. occupant
    Member
    Posted 2 years ago #

    Great to see this is cleared up. I'd also recommend adding the echo to your real-world example on your documentation page.

    So this: <?php echo types_render_field("field-name", array("arg1"=>"val1","arg2"=>"val2")); ?>

    instead of this: <?php types_render_field("field-name", array("arg1"=>"val1","arg2"=>"val2")); ?>

    I added it (my issue was the prefix), but I can see how someone might not. There's never a danger in being too clear.

  12. negs
    Member
    Posted 2 years ago #

    Phew! I had the same problem. I didn't understand that I had to have the echo in there either. And do_shortcode wasn't as helpful because I was showing an image and needed to specify 'medium' and some other parameters. Thanks, everybody.

    I'm really excited about this plugin. Its the cleanest of all the ones out there like it that I have seen. Would like to be able to put 'alignleft' on the image like you can in the wordpress interface.

  13. Ken Dirschl
    Member
    Posted 2 years ago #

    guys, I must concur; you need to put the 'echo' in your example. That's how I ended up here too.

    Seems to be a great plugin; I'll probably check out 'view' as well. Thanks for your work!

  14. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    That's pretty guffy of me. You're right. There's no echo. I added it to the documentation page. Sorry about that.
    http://wp-types.com/documentation/functions/

  15. Ken Dirschl
    Member
    Posted 2 years ago #

    thanks Amir.
    I've been using a blank cpt template up to now, but came across your plugin. I think I'll be switching to Types from now on in. Great plugin. thanks again.
    ken

  16. Vizor
    Member
    Posted 2 years ago #

    Hi guys,

    I'm sorry I cannot make this thing works...I need some help I guess.

    I need to display some custom fields to my posts using "Types".

    After creating the group in Types and setting the conditions, the field is perfectly displaying on my posts in "edit mode". After adding content to the field, it does not shows up on my page in the "online page version".

    To display the field, after reading your answers, I've added the following code to single.php :

    <?php echo types_render_field("vineyard", array("show_name"=>"true","output"=>"html")); ?>

    Unfortunately, nothing happens...

    Any ideas?

    Thanks a lot.

    PS: I still don't have "views" (for the moment ^^)

  17. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    Should be:

    <?php echo(types_render_field("vineyard", array("show_name"=>"true","output"=>"html"))); ?>

  18. pkiula
    Member
    Posted 2 years ago #

    Actually, what's the correct official way to DISPLAY IN A THEME the custom field?

    This should be item no.1 in the FAQ on this plugin page, yet isn't. I shouldn't need the Views plugin to display simple custom fields. Please include a one-liner, at least, in all your documentation, including FAQ here on the plugin page, about how to SHOW the custom fields in the themes.

    Thx

  19. candy2012
    Member
    Posted 2 years ago #

    This plugin has the CREPPIEST explanation ever about how to use it all!
    Guess it was done on purpose? Cause I cannot think of anything else ..

    I could not find ONE single line in the FAQ about HOW on Earth could one display these custom posty types & taxonomies on the page! Is this not all that is all about, dear authors?

    So for this, this plugin did not earn even one single star - it's simply useless, and makes people waste time on it for nothing ...

  20. RoamFree
    Member
    Posted 2 years ago #

    candy2012, I suspect the gap in the documentation is because programmers often forget that people don't know the basic concepts which the programmers learned long ago. In this case, the basic methods of how to make the data be displayed automatically are not documented where we're looking.

    How to manually make data appear is documented, but it's outdated. One of the example pages shows fields being created, and the field editing page includes the shortcodes needed to display the data. The current version of Types has replaced that with a Types shortcode generator (an icon at the top of the edit page, in the same row as the image-insertion icon).

    But inserting a shortcode in the same post which contains the data is only useful in some situations (ie, providing a fill-in-the-blanks tool so someone doesn't have to edit some messy HTML). How to make a certain custom post type emit data automatically is not pointed out -- at least not well enough. Even in the "Views" documentation, they seem to show how to make a page emit data from Types, but I haven't noticed a way to define how a custom post type should be displayed.

    For example, if custom posts are searchable, a search result should find the single entry for a specific house or magazine article (using their Realty and Magazine examples). But how to define the default display for that custom post type is not apparent. We who haven't yet tried it can hope that is because there is an admin menu option which makes such definitions obvious. But it's hard to decide on what technology to use in a site if the needed details are hard to find.

    The Views PHP Integration document does say:
    "Function ‘render_view’
    Renders a view and returns the HTML output."
    That's fine and dandy for a WordPress programmer who knows where to use that. I know plenty of PHP, but for WordPress I know what "the loop" is for, that there seems to be something "single" for posts, and how a plugin hooks in. If there are common places to use that PHP, it would help if those were mentioned.

    (Me, I'm pretty sure that I need Types and Views, but I'm waiting for a reply to a question related to subdomain sensitivity which was sent to them recently.)

  21. RoamFree
    Member
    Posted 2 years ago #

    I'm not sure, but I think step 4 in the View Templates document is what connects a View template to a custom post type. The phrasing mostly can mean that, and I suspect that the image is trying to show a connection being made from a View to a custom post type. A better image would be one which shows the first item (post) with a certain View template already chosen, the second item (page) with that pulldown menu, and text indicating what I'm describing... so we who are trying to confirm our weak understanding can strengthen the certainty of understanding.

    Of course, that only helps those who are using the Views plugin, not those only using Types.

  22. RoamFree
    Member
    Posted 2 years ago #

    I just tried what is in the Views Template document. That does let you define the appearance of a post of a certain type. If you previously used Types to define a custom post type (ie, vehicle or DVD), then you can attach a View template to that post type so when you look at the post it displays what you've defined.

    What is missing from that document is having to go back to Types > Custom Fields, edit the Types, and select that the Type should be displayed with this View Template (click Edit next to "Content templates:"). It seems to not be sufficient to select your custom post type in "Post Types:". When you create a custom post, on the right side should be a pulldown menu to let you select your custom View Template. (EDIT: Hmm... that pulldown menu has also appeared on old non-custom post edit pages also.)

    That still doesn't help a Types-only user to merge Types into their design or theme.

  23. Ken Dirschl
    Member
    Posted 2 years ago #

    @roamfree, @candy2012, @pkiula:

    what you want to look at is the types fields api. The example right at the top explains how to make a Types custom post type appear in your template without using Views.

  24. RoamFree
    Member
    Posted 2 years ago #

    @badfun,

    Yes, that function is also mentioned near the top of this discussion. The documentation for the Types API says "To insert Types fields using PHP code, use the following syntax:" but gives no hint where to insert such code.

    The two hints in "Using Custom Fields" are shortcodes and Views. Shortcodes will only display what is in the current post (or is there a loop-post shortcode?). This discussion seems to be about Types -- and not Views, which does provide ways to display what is in Types.

    Some of us can insert PHP in pages, but that's not a general solution and is probably not what was intended. I suspect this does not belong in the loop either, but I'm not certain.

  25. Ken Dirschl
    Member
    Posted 2 years ago #

    @roamfree,
    The api is for adding the code to your page template, and yes it is in the loop (it's a post type). I've been using it because it is a great way to make a custom post type really fast.

    Here is an example:

    <div class="content">
        <?php the_excerpt(); ?>
        <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'bfportfolio' ) ); ?>
        <p>URL: <a href="<?php echo types_render_field("project_url", array('raw'=>'true'));?>" target="_blank"><?php echo types_render_field("project_url", array('raw'=>'true'));?></a></p>
        <p>Design by: <a href="<?php echo types_render_field("project_design_url", array('raw'=>'true'));?>" target="_blank"><?php echo types_render_field("project_design", array());?></a></p>
    
        <?php wp_link_pages( array( 'before' => '<nav class="page-link" role="navigation">' . __( 'Pages:', 'bfportfolio' ), 'after' => '</nav>' ) ); ?>

    You can see that I've entered in a 'project url' and a 'project design url' metatype, just below the main content, which were set up in the custom post type. This is inside the query that looks only at my custom post type.

    Does that help?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags