• Resolved designerken

    (@kcharity)


    on my single.php file I am able to use:

    <?php echo types_render_field( "nsm-specifications"); ?>

    to render the content on the page when viewing my CPT.

    How do I display the title of the Post Field Name and have it to appear in the front end as well? I assume there is a function for that?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Anonymous User 14808221

    (@anonymized-14808221)

    Do you mean to display the label of the Post Field?

    In that case, you can consult the Programmer Reference Document where we elaborate how to do that.

    As example for the Single Line Field, you can use the attribute show_name and set it to true.

    Thread Starter designerken

    (@kcharity)

    Hi Beda,

    That was what I was looking for, I didn’t have that link.

    types_render_field( 'nsm-specifications', array( 'show_name' => 'true', 'output' => 'html' ) )

    Now my code above will output the label, however is there a way to (1) wrap the label in an “h” tag and (2) remove the colon “:” from after the label? (I’d prefer to do without JS)

    Anonymous User 14808221

    (@anonymized-14808221)

    1. I consider this a BUG.
    The : should not be rendered and I reported it.
    2. No, the whole information is ONE string. Hence, you can only wrap the whole string in an HTML tag.

    But you just output the title manually, not with the Types API (hence, a hard coded title)

    Thread Starter designerken

    (@kcharity)

    Thanks for the update.

    One last thing, is that how it is stored in the database as well (one big string)? There is no way to query it? What table is it stored in?

    Maybe future development of the plug in allows for customizing the output.

    Something like:

    types_render_field('nsm-specifications', array(
    'show_name' => 'true', 'output' => 'html' ,
    'before_name' => '<h2 class="types-name">',
    'after_name' => '</h2>’,
    'before_field' => '<div id="%1$s" class="types-field myclass">',
    'after_field' => '</div>'
    ))
    Anonymous User 14808221

    (@anonymized-14808221)

    You can also use the WordPress API get_post_meta() in this case here.
    It does the same as our API.

    To answer your question how things are stored:
    1. The meta_value is stored in the postmeta table, just like WordPress Fields.
    2. The meta_key also is stored in the postmeta table, just like the WordPress Fields.
    3. The label itself (upper case, not the slug), is in the options table, hence here you need Custom Code to get it.
    It’s a serialized array.
    The types API does that for you, but if you need it stand alone, you need custom code.

    Thread Starter designerken

    (@kcharity)

    Perfect, thanks again @Bedas

    Thread Starter designerken

    (@kcharity)

    For what it’s worth, this is the code I came up with.

    <?php
        $field_slug = 'wpcf-nsm-specifications';
        $field_definition = get_post_meta( $post->ID, $field_slug, true );
        $field_title = str_replace( "wpcf-","", $field_slug );
        $wpcffields = get_option( 'wpcf-fields' );
        if( ! empty( $field_definition ) ) {
            $output = '';  
            $output .= '<div id="' . $field_title . '" class="x-section">';
            $output .= '<div class="x-container max width offset">';
            $output .= '<h2>' . $wpcffields[$field_title]['name'] . '</h2>';
            $output .= sprintf( types_render_field( $field_title, array( 'output' => 'html' ) ) );
            $output .= '</div>';
            $output .= '</div>';
     } ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding field title to front end’ is closed to new replies.