Title: Dynamically change GenerateBlocks QueryLoop
Last modified: December 11, 2023

---

# Dynamically change GenerateBlocks QueryLoop

 *  Resolved [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/)
 * I`m trying to build testimonial blocks, and want to add stars equal to the ACF
   custom field. For now, I have this code:
 *     ```wp-block-code
       $stars_value = get_post_meta(get_the_ID(), 'stars', true);
   
       		// Maximum stars to display
       		$max_stars = 5;
   
       		for ($i = 1; $i <= $max_stars; $i++) {
       			// Check if the current star
       			$star_class = ($i <= $stars_value) ? 'filled' : 'empty';
   
       			echo '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="' . ($star_class === 'filled' ? '#FFC62B' : '#C4C4C4') . '">
                       <path d="M21.8346 9.07699L15.6611 8.63707C15.3727 8.61752 15.1332 8.44644 15.0257 8.1776L12.699 2.444C12.4497 1.833 11.5748 1.833 11.3255 2.444L8.9988 8.1776C8.89126 8.44644 8.65175 8.61752 8.36336 8.63707L2.18983 9.07699C1.52507 9.12587 1.25623 9.95194 1.76458 10.3821L6.50104 14.3658C6.72099 14.5515 6.81387 14.8302 6.74543 15.1137L5.2546 21.121C5.0933 21.7711 5.80205 22.2794 6.36906 21.9275L11.6188 18.6526C11.8632 18.501 12.1564 18.501 12.4057 18.6526L17.6554 21.9275C18.2224 22.2794 18.9263 21.7662 18.765 21.121L17.2742 15.1137C17.2057 14.8302 17.2937 14.5515 17.5186 14.3658L22.255 10.3821C22.7682 9.95194 22.4994 9.12587 21.8346 9.07699Z"/>
                   </svg>';
       		}
       ```
   
 * which works correctly except for the fact that WP get_post_meta(get_the_ID(),‘
   stars’, true); returns the current page ID, which is correct behavior, so I used
   render block to change the query loop block like this:
 *     ```wp-block-code
       add_filter('render_block', function($block_content, $block) {
   
       	if (!empty($block['attrs']['className']) && 'stars-holder' === $block['attrs']['className']) {
       		$stars_value = get_post_meta(get_the_ID(), 'stars', true);
   
       		// Maximum stars to display
       		$max_stars = 5;
   
       		for ($i = 1; $i <= $max_stars; $i++) {
       			// Check if the current star
       			$star_class = ($i <= $stars_value) ? 'filled' : 'empty';
   
       			// Modify the block content here
       			$block_content .= '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="' . ($star_class === 'filled' ? '#FFC62B' : '#C4C4C4') . '">
                       <path d="M21.8346 9.07699L15.6611 8.63707C15.3727 8.61752 15.1332 8.44644 15.0257 8.1776L12.699 2.444C12.4497 1.833 11.5748 1.833 11.3255 2.444L8.9988 8.1776C8.89126 8.44644 8.65175 8.61752 8.36336 8.63707L2.18983 9.07699C1.52507 9.12587 1.25623 9.95194 1.76458 10.3821L6.50104 14.3658C6.72099 14.5515 6.81387 14.8302 6.74543 15.1137L5.2546 21.121C5.0933 21.7711 5.80205 22.2794 6.36906 21.9275L11.6188 18.6526C11.8632 18.501 12.1564 18.501 12.4057 18.6526L17.6554 21.9275C18.2224 22.2794 18.9263 21.7662 18.765 21.121L17.2742 15.1137C17.2057 14.8302 17.2937 14.5515 17.5186 14.3658L22.255 10.3821C22.7682 9.95194 22.4994 9.12587 21.8346 9.07699Z"/>
                   </svg>';
       		}
       	}
   
       	return $block_content;
   
       }, 10, 2);
       ```
   
 * But it’s not working for some reason; perhaps you can help me identify my mistakes?
   Thanks.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdynamically-change-generateblocks-queryloop%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269265)
 * Hi there,
 * Can you first remove the `stars-holder` class from the Grid block and the container
   block? And the class you added to the headline block should’ve been `stars-holder`
   not `stars-holders`.
 * Let me know how it goes.
 *  Thread Starter [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269276)
 * Hey, thank you for your feedback. I’ve made changes.
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269375)
 * I’m still seeing the class on container block, can you make sure only the headine
   block has this class?
 * [https://app.screencast.com/wksGkgdgSIzlN](https://app.screencast.com/wksGkgdgSIzlN)
 *  Thread Starter [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269399)
 * Oh, my bad, now it should be fine
    -  This reply was modified 2 years, 5 months ago by [alyshtva](https://wordpress.org/support/users/alyshtva/).
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269432)
 * Now it should work, if it’s not, make sure:
    1. the custom field slug `stars` is correct.
    2. all of the 3 posts already have the value set in the `stars` field.
 *  Thread Starter [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269477)
 * Oh… I see now. Yes, it’s working. I thought I had misunderstood something, but
   the code itself was pretty much correct. Thank you so much for your help.
 * I wish you a peaceful sky and a great time.
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269479)
 * Glad to hear that 🙂 Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Dynamically change GenerateBlocks QueryLoop’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

## Tags

 * [GB](https://wordpress.org/support/topic-tag/gb/)
 * [query loop](https://wordpress.org/support/topic-tag/query-loop/)

 * 7 replies
 * 2 participants
 * Last reply from: [ying](https://wordpress.org/support/users/yingscarlett/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#post-17269479)
 * Status: resolved