• Resolved shinkibo

    (@shinkibo)


    Hello

    3 blocks, block A, B, C.
    Identical block short code to a script that randomly choose a post in category.
    The only difference is block A choose a random post in category 1, block B in cat 2 and Block C in cat 3.
    Posts are only in one category. So except the category ID, block are strictly identicals.

    Block visibility rules are exactly the same for each block.
    Block A only appears on Category 1
    Block B only appears on Category 2
    Block C only appears on Category 3

    Rules work for block A and B but not for block C.
    If I change the order of the block, let say Block A, C, B then rules work for block A and C but not for block B.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Nick Diego

    (@ndiego)

    Hi @shinkibo,

    Thanks for reaching out. I attempted to replicate the issue using three Group blocks: A, B, C. I then created three new categories: A, B, C. Finally I created three posts, one for each category.

    I tested with the Twenty Twenty-Four theme, so I then when into the Posts template in the Site Editor and added the three Group blocks to the top of the template. I set the Location control on Group A to only is Post Taxonomy > Category > Is at least one of the selected > A. I repeated this step for Group B and C.

    I then visited the A post on the front end and saw Group A. I visited the B post and saw Group B, and the same for Group C.

    Therefore, as far as I can tell, everything is functioning properly. I am wondering if the shortcode might be causing issues. I would try wrapping each shortcode in a Group block (or other container) and place the visibility conditions on the outer container. Let me know if that works.

    Best,
    Nick

    Thread Starter shinkibo

    (@shinkibo)

    Definitely a problem on my side.
    Just made a test with 3 basics html block.
    just like previous example, Block A is supposed to only appear on Category 1, Block B with cat 2 and block C with cat 3.

    First, black A and B appear only if “hide when rules apply” in on. ??
    Block A appears on cat 1, 2 and 3.
    Block B appears ont cat 1 and 2
    Block C appears on cat 3.

    I’ll made more tests and let you know if I find the reason.

    edit : just made a test. If block A, B and C are the very first blocks on page, then Block A and B appears ont cat 1, 2 and 3 and block C never.

    edit 2: if all blocks are in the header, all blocks appear on cat 1, 2, 3….
    ah ah ah!!!

    edit 3 : if block between title and post content, everything work fine ??

    • This reply was modified 4 months, 1 week ago by shinkibo.
    • This reply was modified 4 months, 1 week ago by shinkibo.
    • This reply was modified 4 months, 1 week ago by shinkibo.
    Plugin Author Nick Diego

    (@ndiego)

    Hi @shinkibo,

    I apologize for the delayed reply. It took me a long time to replicate this issue, which appears to be isolated to the HTML block. Something about the way this block is rendered by WordPress itself is strange, but I did find a solution.

    It seems that if the HTML block is contained inside of another block, such as a Group block, the visibility conditions are respected. This is not unique to Block Visibility.

    I did some additional tests adding custom functionality to the HTML block. Without the block being wrapped in another container, the custom functionality is not respected.

    You can test this by adding the following filter to the functions.php file of your theme, and then inserting a HTML block in a block template without any container.

    function append_testing_to_html_block( $block_content, $block ) {
    // Check if the block is an HTML block and has content.
    if ( 'core/html' === $block['blockName'] && $block_content ) {
    // Append the word "testing" to the block content.
    $block_content .= ' testing';
    }

    return $block_content;
    }
    add_filter( 'render_block', 'append_testing_to_html_block', 100, 2 );

    Since this issue does not appear to be related to Block Visibility, I am going to close this issue, but I’ll report it in the Gutenberg repository so this issue can be solved in Core WordPress.

    Thanks,
    Nick

    Plugin Author Nick Diego

    (@ndiego)

    For reference, I opened the issue here: https://github.com/WordPress/gutenberg/issues/64420

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.