• Hi everybody !
    I am from Viet Nam and my english is very poor. I am a beginer. I have problem when i try to display some custom file on my index website.
    I created 2 custom field: Giá: 120.000 and Size: XL. I want to display value of key ‘Giá’ in each product on my index website.
    I try to use code: get_post_meta(get_the_ID(),’Giá’,true) in index.php and single.php but it doesn’t work.

    But when i used the same above code in category.php it work. I don’t understand what is problem. Who can help me please. Thanks you so much. I am very look forward to yours replay !

Viewing 4 replies - 1 through 4 (of 4 total)
  • Could you post the code from your index.php file?

    Thread Starter tienduydng

    (@tienduydng)

    This is code in index.php. It doesn’t work.

    get_header(); ?>
    <div class=”spnoibat”></div>
    <div class=”leftpanel”>
    <?php include ‘sanpham.php’; ?>
    </div>
    <div id=”content” class=”site-content” role=”main”>
    <?php /* The loop */ ?>
    <?php
    $arg = array(
    ‘post_type’ => ‘post’
    );
    $query = new $wp_query($arg);
    while($query->have_posts()): $query->the_post();

    ?>
    <div class=”loadcontent”>
    <div class=”hinh”>“><?php echo the_post_thumbnail();?></div>
    <div class=”info”>“><?php the_title(); ?>
    <?php echo get_post_meta(get_the_ID(),’Giá’,true); ?></div>
    </div>
    <?php endwhile; ?>
    </div><!– #content –>

    And this is code in category.php. It work !

    get_header(); ?>
    <div class=”spnoibat”></div>
    <div class=”menunav”>
    <?php
    //get id of current category
    $id = get_query_var(‘cat’);
    // get category parent
    $nav = get_category_parents($id,true,'<span class=”navi”></span>’);?>
    “>Trang ch?<span class=”navi”><?php echo $nav;?></span>
    </div>
    <div class=”leftpanel”>
    <?php include ‘sanpham.php’; ?>
    </div>
    <div id=”content” class=”site-content” role=”main”>
    <?php while ( have_posts() ) : the_post(); ?>
    <div class=”loadcontent”>
    <div class=”hinh”>“><?php the_post_thumbnail();?></div>
    <div class=”info”>“><?php the_title(); ?>
    <?php echo get_post_meta(get_the_ID(),’Giá’,true); ?></div>
    </div>
    <?php endwhile; ?>

    </div><!– #content –>

    Thread Starter tienduydng

    (@tienduydng)

    My custom field: key: Giá value: 120000
    I want to get value 120000 and display on index page.

    Is anything showing from the loop on the index.php page?

    I believe:

    $query = new $wp_query($arg);

    should be:

    $query = new WP_Query($arg);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can't display custom field’ is closed to new replies.