A good friend on mine solved the issue. Here is the working code:
// Use 1 column layout for art series with one work ACF based
function vv_custom_cat_layout( $options ) {
$terms = get_terms([
'taxonomy' => 'product_cat',
'hide_empty' => true,
'meta_query' => [
'key' => 'series_one_work',
'value' => 1
]
]);
$AcfFilter = [];
foreach($terms as $term)
array_push($AcfFilter, $term->slug); // i'm never sure if is term_name or just name, sorry
if ( is_product_category( $AcfFilter ) )
$options['columns'] = 1;
return $options;
}
add_filter( 'option_generate_woocommerce_settings','vv_custom_cat_layout' );
Thanks @vverner for all your help! really appreciated.
Not working yet…
I tested with name, term_name and $term->slug
. Nothing works.
I tried writing the slug manually, for example
if ( is_product_category( 'biota') )$options['columns'] = 1;
and it works, so the problem might be in the array_push?
Thanks so much @vverner!
I tested with:
'taxonomy' => 'post_tag',
and
'taxonomy' => 'product_cat',
But is not working. Remember this is a WooCommerce product category…
Here are the other values:
'hide_empty' => true,
'meta_key' => 'series_one_work',
'meta_value' => '1'
Any other suggestion?
Thank you, I tried a few options but I am doing something wrong…
I get the 1 column layout applied to every category
/*Use 1 column layout for art series with one work*/
add_filter( 'option_generate_woocommerce_settings','lh_custom_category_wc_columns' );
function lh_custom_category_wc_columns( $options ) {
if ( $query->query_vars['product_cat'] ) {
$query->set('meta_key', 'series_one_work');
$query->set('meta_value', '1');
}
{
$options['columns'] = 1;
}
return $options;
}
AMAZING!
Thanks a lot, I was becoming crazy trying to make it work.
So I guess I don’t need to use anything extra to get the gallery values into the script, right?
And could it be possible to load different image sizes depending on the device? I guess this is a question for Backstrech forum or Zurb Foundation (I use a theme based on Zurb Foundation)
Anyway, this is the working code in case anyone wants to do something similar
Note: This gallery field is part of a options page, and jQuery Backstrech needs to be enqueued.
<?php
// Get the ACF gallery images
$images = get_field('slideshow_gallery', 'option');
?>
<script>
//Backstretch slideshow
// Duration is the amount of time in between slides,
// and fade is value that determines how quickly the next image will fade in
$.backstretch([
<?php
foreach( $images as $image ) {
echo '"' . $image['url'] . '",';
}
?>
], {
duration: 3000,
fade: 750
});
</script>
Thanks @James
I am not a programmer and I don’t really understand how this can be done.
The main problem for me is how to get an array of image URLs from the gallery field (it is part of a Options page) and how to make them a variable. I checked how a WP gallery shortcode is done https://www.advancedcustomfields.com/resources/gallery/ but instead of the IDs I need the URL. I also tried using implode to add commas between values, but couldn’t make it work.
Could you please guide me into the right direction to solve this??
My not-working code is below. Thanks!
<!-- trying to get the array of URLs -->
<?php
$images = get_field('slideshow_gallery', 'option');
if( $images ):
foreach( $images as $image ): ?>
<?php echo $image['url']; ?>,
<br>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Put the URLs inside a div -->
<div id="dom-target" style="display: none;">
<?php
$output = "image01", "image02", "image03"; //just a test
echo htmlspecialchars($output); /* You have to escape because the result will not be valid HTML otherwise. */
?>
</div>
<!-- Put the content into a variable -->
<script>
var div = document.getElementById("dom-target");
var myData = div.textContent;
</script>
<script> /* Build backstretch slideshow */
// Duration is the amount of time in between slides,
// and fade is value that determines how quickly the next image will fade in
$.backstretch([
myData
], {
duration: 3000,
fade: 750
});
</script>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.