WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display custom fields for custom post type (2 posts)

  1. oriolo
    Member
    Posted 1 year ago #

    I'm trying to display on the site custom fields, that are created for custom post type. I have to display "price" and "description".
    I've made file content-user.php:

    $price = get_post_meta( get_the_ID(), 'goods_price', true );
        $excerpt = theme_get_excerpt();
        $descr = array( $price, $excerpt );
        global $post;
        theme_post_wrapper(
            array(  'id' => theme_get_post_id(),
                    'class' => theme_get_post_class(),
                    'thumbnail' => theme_get_post_thumbnail(),
                    'title' => '<a href="' . get_permalink( $post->ID ) . '" rel="bookmark" title="' . strip_tags(get_the_title()) . '">' . get_the_title() . '</a>',
            'heading' => theme_get_option('theme_'.(is_single()?'single':'posts').'_article_title_tag'),
                    'before' => theme_get_metadata_icons( 'category,edit', 'header' ),
                    'content' => $descr,
                    'after' => '' ));

    So I have a word "Array" in the page of single post. If I replace $descr = array( $price, $excerpt ); with $descr =$price; or $descr = $excerpt; I have or price, or description.

    What I need to put in content-user.php to see price and description in the content?

  2. bcworkz
    Member
    Posted 1 year ago #

    $descr needs to be a string, your theme wrapper doesn't know how to deal with arrays, so build a single string out of various elements like so:
    $descr = $price . '<br>' . $excerpt;
    You can rearrange and add or remove HTML as needed to get the desired effect.

Topic Closed

This topic has been closed to new replies.

About this Topic