Support

Account

Forum Replies Created

  • Hi @astrixoblix, it works.
    Thank u and @elliot. And I wanna go farther. As the image shown in my first post, I want to show 3 related produces. Now I repeat the code 3 times.

    $related_1 = 
    ...
    $related_2 = 
    ...
    $related_3 = 
    ...

    is it stupid? Any better idea?

    Here are the codes generated by ACF:

    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_releated-products',
    		'title' => 'Releated Products',
    		'fields' => array (
    			array (
    				'key' => 'field_5296d411901eb',
    				'label' => '1st related product',
    				'name' => '1_related_product',
    				'type' => 'post_object',
    				'post_type' => array (
    					0 => 'product',
    				),
    				'taxonomy' => array (
    					0 => 'product_category:213',
    				),
    				'allow_null' => 1,
    				'multiple' => 0,
    			),
    			array (
    				'key' => 'field_5296d53cf9d3e',
    				'label' => '2nd related product',
    				'name' => '2_related_product',
    				'type' => 'post_object',
    				'post_type' => array (
    					0 => 'product',
    				),
    				'taxonomy' => array (
    					0 => 'product_category:213',
    				),
    				'allow_null' => 1,
    				'multiple' => 0,
    			)
    ...
  • Many tks, @elliot.
    Still got a problem. As the code demo above, the link target right, but the thumbnail shown nothing. I’m sure the target post thumbnail was set.
    There are TWO custome field set, checkbox and post object, they will work well?
    I custom a post type “product”, and set a taxonomy “product_category” for it, the code is placed in the loop of taxonomy-product_category.php. My code following:

    <?php if ( have_posts() ) : ?>
    	<?php while ( have_posts() ) : the_post(); ?>
    		<article>
    			<h1></h1>
    			<?php
    				the_content();
    
    				// FIRST CUSTOM FIELD: CHECKBOX FIELD
    				$values = get_field( 'feature' );
    				if ($values) {
    					foreach( $values as $value ) {
    						echo '<span class="label label-feature">' . $value . '</span>'; //WORKING WELL
    					}
    				}
    				
    				// SECOND FIELD: POST OBJECT
    				$related_1 = get_field( '1_related_product' );
    					if( $related_1 ) {
    						echo '<a href="' . get_permalink( $related_1 ) . '">'; // WORKING WELL
    							echo get_the_post_thumbnail( $related_1 ); // RETURN NOTHING
    						echo '</a>';
    					}
    				?>
    				
    				...
Viewing 2 posts - 1 through 2 (of 2 total)