- This topic has 5 replies, 2 voices, and was last updated 3 years, 5 months ago by
Fernando.
-
AuthorPosts
-
November 2, 2022 at 6:47 pm #2399188
Jason
Hey y’all. I seem to be getting stupid with query loop blocks. You came through last time with the image array, now I need to do something similar with a number ACF field, and I’m sure I’m just messing up the syntax.
In a nutshell, I have 3 product price fields:
pdf_price
pod_price
product_priceFor the archive and single pages, an if statement checking if the field has value and then displaying it WORKS (then using a shortcode with the portable hook shortcode method). This doesn’t work for the query loop, as I learned on the last go-round with the images. Here is the code you gave me to display images (set to array with logic) in a query loop:
add_filter( 'render_block', function( $block_content, $block ) { $image = get_field('product_main_image'); if ( !is_admin() && $image && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'my-query-header' ) !== false ) { $block_content = '<img class="product-main-image" src="' . esc_url($image['url']) . '" class="product-main-image" alt="' . esc_attr($image['alt']) . '"/>'; } return $block_content; }, 10, 2 );Giving any block in the query loop the class of “my-query-header” displays the image beautifully. Now – how do I do the same thing with 3 different number fields? (if no data exists in a particular field, it shouldn’t display)
Thanks, as always for your time.
November 2, 2022 at 8:28 pm #2399234Fernando Customer Support
Hi Jason,
Have you tried directly getting it from the Dynamic settings of the Headline Block?
Just set the source to Post Meta and the Post meta field to the custom field slug.
By default, it shouldn’t display anything if the meta is null.
Let us know.
November 2, 2022 at 8:39 pm #2399241Jason
Perfect – I just added three headline blocks and set them to their respective post meta names. It works! I was overthinking it, per usual. Thank you so much! You guys are awesome.
November 2, 2022 at 8:53 pm #2399255Fernando Customer Support
You’re welcome Jason!
November 3, 2022 at 8:34 pm #2400844Jason
Marked as resolved. Thanks, again
November 3, 2022 at 8:43 pm #2400853Fernando Customer Support
You’re welcome Jason! Glad to be of assistance!
-
AuthorPosts
- You must be logged in to reply to this topic.