I would suggest two solutions.
Solution:1 Use WP_Query, if there are only few products, may be 10 or 20
Use WP_Query, loop through all the products, check if transmission_URL
is not empty, if it is not empty, print the link and break from the loop.
The following code snippet goes inside header.php
$product_query = new WP_Query( array(
'post_type' => 'product'
) );
if( $product_query->have_posts() ):
while( $product_query->have_posts() ): $product_query->the_post();
$transmissionURL = get_field('transmission_URL');
if (! empty( $transmissionURL ) ) :
echo '<a href="https://wordpress.stackexchange.com/questions/272458/URL-to-product-which-have-active-transmission" class="btn">LIVE</a>';
break; // come out of while loop entirely, cause we are done.
else:
continue; // skip to the next product, stay inside while loop.
endif;
endwhile;
endif;
Solution 2: Make use of categories.
If the product count is high or If you want to save some maintenance time,
Create and assign a new category active-transmission
to product_cat
taxonomy. Then you can just query for the product with category active-transmission
. This also allows to track previously transmission-ed product easily.
$product_query = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 1, // pull out only one product from the category
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'active-transmission',
),
),
) );
if( $product_query->have_posts() ):
while( $product_query->have_posts() ): $product_query->the_post();
$transmissionURL = get_field('transmission_URL');
if (! empty( $transmissionURL ) ) :
echo '<a href="https://wordpress.stackexchange.com/questions/272458/URL-to-product-which-have-active-transmission" class="btn">LIVE</a>';
endif;
endwhile;
endif;
You can modify the If blocks based on your requirements.