• xuv

    (@juego)


    I’m using the code editor to get a query loop to exclude some posts in its results. I?can see it visually working in the visual editor, but when checking the website, it’s not takin into account.

    I’m using the twenty twenty-three theme. And I have modified the All Archives template. I’m expecting to see the exclusion of posts in all the tags, category and author pages. But it’s not working.

    Any suggestion? What am I missing? Thx

    • This topic was modified 1 year ago by xuv.
    • This topic was modified 1 year ago by xuv.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator jordesign

    (@jordesign)

    Hi @juego,

    One thing that could be happening is that the extra code you’re adding in the code view is actually stripped out on saving (as the Query Loop block doesn’t expect it).

    If you publish/update the page and then reload it in the editor – are the exclusions still in place in the code?

    Thread Starter xuv

    (@juego)

    Hi @jordesign,

    Thanks for the suggestion. I did check that. And the information I’m adding is saved. I did publish the page. I can even log out and come back to it. The list of IDs I added in the exclude array is still there.

    It’s as if when in editor mode, it would take it into account, but when on a public page, it would just wipe the array blank.

    I kind of solved my problem by adding a specific action in my theme function.php to exclude those articles from the query. So that’s solved my problem. But I still think there is something not working properly or as expected.

    Moderator jordesign

    (@jordesign)

    Hi @juego – thanks for checking that. It’s very interesting to know.

    Glad to hear you’ve found a workaround to the problem – but agreed it would still be good to know what is happening there.

    If you check the code of that Query Loop block would you be willing to paste it into a code block in this thread – so I can test it out?

    Thread Starter xuv

    (@juego)

    Hello @jordesign

    Sure. Here is the code. It’ actually the vanilla All Archives Template from the Twenty Twenty-Three official theme, with just the exclude array being changed to contain a list of post IDs.

    <!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
    
    <!-- wp:group {"tagName":"main","style":{"spacing":{"margin":{"top":"var:preset|spacing|70","bottom":"var:preset|spacing|70"}}},"layout":{"type":"constrained"}} -->
    <main class="wp-block-group" style="margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)"><!-- wp:query-title {"type":"archive","align":"wide","style":{"spacing":{"margin":{"bottom":"var:preset|spacing|50"}}}} /-->
    
    <!-- wp:query {"queryId":3,"query":{"perPage":9,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[220, 225, 227, 228, 5, 6, 7, 8, 9, 10, 11, 20, 22, 24, 26, 27, 104, 29, 112, 110, 100, 90, 76, 102, 94, 81, 88, 96, 98, 78, 92, 106, 74, 72, 70, 86, 84, 85, 67, 66, 64, 62, 60, 58, 56],"sticky":"","inherit":true,"taxQuery":null,"parents":[]},"className":"alignwide"} -->
    <div class="wp-block-query alignwide"><!-- wp:post-template {"align":"wide","layout":{"type":"grid","columnCount":3}} -->
    <!-- wp:post-featured-image {"isLink":true,"width":"100%","height":"clamp(15vw, 30vh, 400px)","align":"wide"} /-->
    
    <!-- wp:post-title {"isLink":true} /-->
    
    <!-- wp:post-excerpt /-->
    
    <!-- wp:spacer {"height":"var(\u002d\u002dwp\u002d\u002dpreset\u002d\u002dspacing\u002d\u002d50)"} -->
    <div style="height:var(--wp--preset--spacing--50)" aria-hidden="true" class="wp-block-spacer"></div>
    <!-- /wp:spacer -->
    <!-- /wp:post-template -->
    
    <!-- wp:query-pagination {"paginationArrow":"arrow","layout":{"type":"flex","justifyContent":"space-between"}} -->
    <!-- wp:query-pagination-previous {"label":"Newer Posts"} /-->
    
    <!-- wp:query-pagination-next {"label":"Older Posts"} /-->
    <!-- /wp:query-pagination --></div>
    <!-- /wp:query --></main>
    <!-- /wp:group -->
    
    <!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->

    Hope this helps

    Julien

    • This reply was modified 12 months ago by xuv.
    Plugin Author Nik Tsekouras

    (@ntsekouras)

    Hey! There are a couple of things going on here, but in general this is not a bug.

    In some initial steps when implementing Query Loop block, we had added the exclude argument, but while it’s kind of supported as an option(do it manually and have a workaround), is not officially supported because it will need proper handling and expose UI controls for it.

    Having said that, this(exclude) and other arguments are ignored when we inherit the query from the template and that’s your case in the archive template(you have inherit:true).

    The last thing to mention is the mismatch between editor and front-end. When we inherit the query from the template there is no supported way right now to get the arguments that we would have in front end(the final built WP_Query used) in the editor. So in essence what you see in editor is custom query that tries to match as match as possible the front-end. The reason for that is for example if we have a category template it will be used by any category in a site, so we need to make some decisions to try to match as much we can per template.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Excluding posts by ID in Query Loop works in the editor but not on public site’ is closed to new replies.