Skip to content

Instantly share code, notes, and snippets.

@ashleycam3ron
Last active March 3, 2020 00:31
Show Gist options
  • Save ashleycam3ron/9974169269474ec5d89132d937198a6e to your computer and use it in GitHub Desktop.
Save ashleycam3ron/9974169269474ec5d89132d937198a6e to your computer and use it in GitHub Desktop.
Get software notes for firmware updates equal to user's products
<?php // Software notes
if( have_rows('products', $userID) ): ?>
<?php while( have_rows('products', $userID) ): the_row();
$product = get_sub_field('product'); //get repeater post object
if ($product):
//print_r($product);
$productpost = $product;
setup_postdata( $productpost ); ?>
<?php //while there are software update posts
while ( have_posts() ) : the_post(); ?>
<?php if (!in_category( 'archive' )){ ?>
<?php // Get product update product_relationship
$relationship = get_field('product_relationship');
if( $relationship ):
// Have I shown the heading = false
$i = false;
foreach( $relationship as $product) : ?>
<?php //if user product ID equals firmware relationship ID
if ( $productpost->ID === $product->ID){
$productID = $product->ID;
$note = get_field('notes');
if ($note){ ?>
<div class="notes clear">
<?php if (!$i){ // If I have not shown the heading, show the heading
$i = true; // record that I've shown the heading
?>
<h3>Software Notes</h3>
<?php } ?>
<?php //the_title();?>
<?php echo $note;?>
</div>
<?php } ?>
<?php } ?>
<?php endforeach; ?>
<?php endif; //end product_relationship ?>
<?php } //end check for archive ?>
<?php endwhile; ?>
<?php //rewind_posts(); ?>
<?php wp_reset_postdata(); //reset user productpost setup ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
@paulcushing
Copy link

Hmm. Not sure what we missed. Here's what should be pretty much the same thing but cleaned up a little. I'm assuming you also want the heading outside of the <div class="notes clear">.

<?php // Get product update product_relationship
	$relationship = get_field('product_relationship');
    
    if( $relationship ):

        $headingshown = false;

        foreach( $relationship as $product) :
            //if user product ID equals firmware relationship ID
			if ( $productpost->ID === $product->ID){ 

				$productID = $product->ID;
				$note = get_field('notes');

				if ($note) { 
                                     if (!$headingshown) {
                                         echo "<h3>Software Notes</h3>";
                                         $headingshown = true;
                                     } ?>
					<div class="notes clear">
					    <?php //the_title();?>
					    <?php echo $note; ?>
					</div>
				<?php } ?>
		<?php } ?>

    <?php endforeach; ?>

<?php endif; //end product_relationship ?>

@ashleycam3ron
Copy link
Author

ashleycam3ron commented Mar 3, 2020

Hi @paulcushing - thanks for taking time to look at this! I was hoping I wouldn't have to post the whole code, but there are a lot of layers going on here. I just updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment