Last active
March 3, 2020 00:31
-
-
Save ashleycam3ron/9974169269474ec5d89132d937198a6e to your computer and use it in GitHub Desktop.
Get software notes for firmware updates equal to user's products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
Author
ashleycam3ron
commented
Mar 2, 2020
The alternative suggested in the FB group was a good one. You could just use $i as a switch. Initiate it to false, then just change it to true when you load the title, and check for !$i to show the title.
<?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');
echo '<div class="clear">'.$i.'</div>';
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 ?>
Thank you @paulcushing . I tried this and here's the output:
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 ?>
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