Use GB query loop for Related Post

Yes, vinetas it is one of the main and most used categories.

I’ve updated the original code to use tax_query instead. Let’s see if it fixes the issue :slight_smile:

Good morning Tom :coffee:
Critical error in frontend for: Unexpected ’ } ’

Ugh, typing code in here can be a pain. Should be good to go now.

Thank you Tom
The code no longer gives errors but still doesn’t show related.
I’ll wait for the final version so I don’t steal any more of your time with this issue. Have a good job.

Hi there,

Sorry for the delay, I’ve tested it with GB 1.5.0-rc.1 and it’s working for me, no problems, no errors, except two things:

  • When a post has 2 category terms, it’s not displaying any related posts.

  • It’s displaying same related posts for all posts in same category. Would it be possible to have something more “random” ?

Thanks !
Sam

I get the same results as described by @Samlaflam

But I also find errors when saving the filter ( screenshot error-1)

And when accessing to edit it from the admin bar in a post and also from the list (screenshot error-2)

Hi @jrmora,

Can you try updating to GB version 1.5.0-rc.2 and see how it goes?: GenerateBlocks 1.5 - Dynamic Data, Query Loops, & Image Blocks - GenerateBlocks

Hi, @fernandoazarcon2

I upgraded to rc.2 and it didn’t fix it, this is the error log:

URL: staging.jrmora.com
WordPress versión 6.0
Active Theme: GeneratePress Child (versión 0.1)
PHP versión 8.1.1

Error details:

Se ha producido un error del tipo E_ERROR en la línea 303 del archivo public_html/staging/wp-content/themes/generatepress_child/functions.php. Mensaje de error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, WP_Error given in public_html/staging/wp-content/themes/generatepress_child/functions.php:303

Stack trace:
#0 public_html/staging/wp-includes/class-wp-hook.php(309): {closure}()
#1 public_html/staging/wp-includes/plugin.php(191): WP_Hook->apply_filters()
#2 public_html/staging/wp-content/plugins/generateblocks/includes/class-render-blocks.php(417): apply_filters()
#3 public_html/staging/wp-content/plugins/generateblocks/includes/class-render-blocks.php(317): GenerateBlocks_Render_Block->do_post_template()
#4 public_html/staging/wp-includes/class-wp-block.php(255): GenerateBlocks_Render_Block->do_grid_block()
#5 public_html/staging/wp-includes/class-wp-block.php(241): WP_Block->render()
#6 public_html/staging/wp-includes/blocks.php(901): WP_Block->render()
#7 public_html/staging/wp-includes/blocks.php(939): render_block()
#8 public_html/staging/wp-includes/class-wp-hook.php(307): do_blocks()
#9 public_html/staging/wp-includes/plugin.php(191): WP_Hook->apply_filters()
#10 public_html/staging/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1811): apply_filters()
#11 public_html/staging/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(560): WP_REST_Posts_Controller->prepare_item_for_response()
#12 public_html/staging/wp-includes/rest-api/class-wp-rest-server.php(1143): WP_REST_Posts_Controller->get_item()
#13 public_html/staging/wp-includes/rest-api/class-wp-rest-server.php(990): WP_REST_Server->respond_to_request()
#14 public_html/staging/wp-includes/rest-api.php(519): WP_REST_Server->dispatch()
#15 public_html/staging/wp-includes/rest-api.php(2868): rest_do_request()
#16 [internal function]: rest_preload_api_request()
#17 public_html/staging/wp-includes/block-editor.php(601): array_reduce()
#18 public_html/staging/wp-admin/edit-form-blocks.php(75): block_editor_rest_api_preload()
#19 public_html/staging/wp-admin/post.php(187): require(’ …’)
#20 {main}
thrown

Hi, is there any news about these two issues ?

  1. When a post has 2 category terms, it’s not displaying any related posts.
  1. It’s displaying same related posts for all posts in same category. Would it be possible to have something more “random” ?

Thanks !

1 Like

Hi!
I’ve tried the snippet above.
1st: Current post should be excluded.
2nd: Any chances to develop some more clever algorithm?
incorporate filtering also by tags?
(the more common tags - the higher index)

2 Likes