1

I registered custom post type in functions.php like so:

function ourproducts_post_type() {

   /*Labels*/
  $labels = array(
    'name' => _x("Our Products", "post type general name"),
    'singular_name' => _x("Our Products", "post type singular name"),
    'menu_name' => 'Our Products',
    'add_new' => _x("Add New", "ourproducts item"),
    'add_new_item' => __("Add New Product Category"),
    'edit_item' => __("Edit Product category"),
    'new_item' => __("New Product Category"),
    'view_item' => __("View Product Category"),
    'search_items' => __("Search Product categories"),
    'not_found' =>  __("No Product categories Found"),
    'not_found_in_trash' => __("No Product Categories Found in Trash"),
    'parent_item_colon' => ''
  );

  /*Register ourproducts post type*/
  register_post_type('ourproducts' , array(
    'labels' => $labels,
    'public' => true,
    'orderby' => 'menu_order', 
    'has_archive' => false,
    'menu_icon' => 'dashicons-groups',
    'rewrite' => false,
    'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
    'show_ui'             => true, 
    'show_in_menu'        => 'custom-options',
    //'menu_position'       => 40,

  ) );
}
add_action( 'init', 'ourproducts_post_type', 0 );

On front-end (on front-page.php template page), I tried displaying the field value outside the loop like so:

    <h3><?php the_field('nasi_proizvodi', $post->ID); ?></h3>

Also, I tried inside the loop like so:

<?php while ( have_posts() ) : the_post(); ?>

            <h3><?php the_field('nasi_proizvodi'); ?></h3>

<?php endwhile;  ?>

But nothing shows. Unless I specifically write the post id like so:

<?php while ( have_posts() ) : the_post(); ?>

            <h3><?php the_field('nasi_proizvodi', 4268); ?></h3>

<?php endwhile;

But I need them dynamically changed, not only for this particular post id. What's funny is that I've already created several text fields on the front-page already(I am developing a theme) and I had no problem dynamically displaying those. What am I doing wrong, any suggestions, please?

  • please check print $post->ID; front-page.php fetch only current page id so – Dharmishtha Patel Jun 28 '18 at 12:05
  • Hi @DharmishthaPatel, thanx for the reply. I just did - the value printed is 4076. I do not know what this value belongs to, i don't see anything with 4076 value. I am confused. – Nancy Jun 28 '18 at 12:07
  • which post id value you need? 4076 is current page id? – Dharmishtha Patel Jun 28 '18 at 12:11
  • please print global $wp_query; echo $wp_query->post->ID; out of loop which page id has print? – Dharmishtha Patel Jun 28 '18 at 12:13
  • As far as I can see, 82 is the front page id. I need for 4268, but not only for that one. I need them dynamically created, as i explained in my question. – Nancy Jun 28 '18 at 12:14
2

please check your postype and add arg

<?php 
$query = new WP_Query( array( 'post_type' => 'ourproducts' ) );
if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : 
        $query->the_post(); 
?>
        <h3><?php echo get_field('nasi_proizvodi'); ?></h3>
<?php 
    endwhile; 
    wp_reset_postdata(); 
endif; 
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.