Support

Account

Home Forums General Issues Get custom fields from custom post type built with blocks

Helping

Get custom fields from custom post type built with blocks

  • Hello, I created a Custom Post Type “Products”. Every product page is built via ACF blocks I registered (not a template page). Now, I want to loop some fields of those blocks in a single page with a loop. For doing that I used a Post Object block with which I can select the custom posts but in in the code of this page I can’t get the fields of the single product I need.

    Here is the code:

    <?php
    global $post;
    
    $post_object = get_field('products'); // this is the Post Object block
    
    if( $post_object ): ?>
    <section class="p-product-archive">
    	<div class="container">
    		<div class="row">
    			<?php foreach( $post_object as $post ): ?>
    				<?php setup_postdata($post); ?>
    			
    				<div class="p-product-thumb col-md-3 col-sm-6 col-6">
    					<a href="<?php the_permalink($post->ID); ?>">// I can get this
    						<div class="p-name"><?php the_field('product_name', $post->ID); ?> // I cannot get this </div>
    					</a>
    				</div>
    			<?php endforeach; ?>
    			<?php wp_reset_postdata(); ?>
    		</div>
    	</div>
    </section>
    <?php endif; ?>

    Anyone can help?
    Thanks a lot,
    Paolo

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.