Support

Account

Forum Replies Created

  • Hi @zaphod, you are not the only one)
    I was struggling an hour until I found this post.
    I don’t understand why they did so.
    For example, I want to have a folder called “acf-block-json” in my plugin, and have all the block json files within it. I don’t like the template rendering, so I don’t have a file/folder structure for block templates. Instead, I have all the blocks as HTML rendering functions.
    Now, with this limitation, I can’t achieve that. But I think the limiation comes fro WP itself.

  • If I understand you right, you have a related “addon” (one post of type “addon”) on this post through “add_on_suites” field.

    If that’s correct, then you just need to check in every iteration which is the needed “addon” by adding a comparison operation like this: $related_addon_id == $addon->ID

    Here is the code:

    <?php 
        $addons = get_posts(array(
          'post_type' => 'addons',
          'posts_per_page' => -1 
        ));
    
        ?>
        <?php if( $addons ): $related_addon_id = get_field('add_ons_suites'); ?>
    	<table class="table table-hover table-sm inclusions">
    	  <thead>
    	    <tr>
    		<th colspan="2" scope="colgroup" class="text-uppercase">Product Inclusion</th>
    	    </tr>
    	  </thead>
    	  <tbody>
    	      <?php foreach( $addons as $addon ): ?>
    		<tr>
    		  <td>
    		  <a href="<?php echo get_permalink( $addon->ID ); ?>">
    		  <i class="fas fa-chevron-right mr-1"></i><?php echo get_the_title( $addon->ID ); ?></a>
    		  </td>
    		  <td>
    		    <?php if( $related_addon_id == $addon->ID ): ?><i class="fas fa-check"></i>
    		    <?php else: ?>
    		     <i class="fas fa-times"></i>
    		    <?php endif; ?>
                      </td>
    		</tr>
                <?php endforeach; ?>
    	</tbody>
    	</table>
    <?php endif; ?>
  • You have a small mistake in the function parameters.
    Just replace the comma with a dot.
    Should be like this:
    $test_desc = get_field( ‘custom_desc’, $term_tax . ‘_’ . $term_id );
    or
    $test_desc = get_field( ‘custom_desc’, ‘term_’ . $term_id );

    Here is the doc:
    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

  • You forgot to set the postdata in foreach loop.
    Just add this after the foreach line: setup_postdata($addon);

    Here is the doc: https://developer.wordpress.org/reference/functions/setup_postdata/

    That will set the $addon as the main $post for every iteration in foreach loop.

    As an alternative solution, you could also add the needed post_id in ACF’s get_field method like this:
    get_field(‘add_ons_suites’, $addon->ID)

    That will bring the acf field data for that specific post

Viewing 5 posts - 1 through 5 (of 5 total)