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

---

# Dynamically change GenerateBlocks QueryLoop

 *  [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/dynamicaly-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';
   
       			// Modify the block content here
       			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.
    -  This topic was modified 2 years, 6 months ago by [alyshtva](https://wordpress.org/support/users/alyshtva/).
    -  This topic was modified 2 years, 6 months ago by [alyshtva](https://wordpress.org/support/users/alyshtva/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdynamicaly-change-generateblocks-queryloop%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/dynamicaly-change-generateblocks-queryloop/#post-17269095)
 * Hi there,
 * This is the support forum for GeneratePress, any chance you can post your question
   in GenerateBlocks’ forum? [https://wordpress.org/support/plugin/generateblocks/](https://wordpress.org/support/plugin/generateblocks/)
 * Thanks!
 *  Thread Starter [alyshtva](https://wordpress.org/support/users/alyshtva/)
 * (@alyshtva)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/dynamicaly-change-generateblocks-queryloop/#post-17269171)
 * Sure, [https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#new-topic-0](https://wordpress.org/support/topic/dynamically-change-generateblocks-queryloop/#new-topic-0)
 *  [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/dynamicaly-change-generateblocks-queryloop/#post-17269292)
 * Just replied on your topic in GB forum.

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

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

 * ![](https://i0.wp.com/themes.svn.wordpress.org/generatepress/3.6.1/screenshot.
   png)
 * GeneratePress
 * [Support Threads](https://wordpress.org/support/theme/generatepress/)
 * [Active Topics](https://wordpress.org/support/theme/generatepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/generatepress/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/generatepress/reviews/)

## Tags

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

 * 3 replies
 * 2 participants
 * Last reply from: [ying](https://wordpress.org/support/users/yingscarlett/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/dynamicaly-change-generateblocks-queryloop/#post-17269292)
 * Status: not resolved