• dkrape

    (@dkrape)


    Hello,

    I am building my first theme with the full site editor.

    On the index page, I have several query blocks that show posts from specific categories. It seems that selecting queries hard-codes the category IDs into the theme template file.

    We’re using GIT to handle version control and have dev, staging, and production sites. I’d very much prefer to not replicate the database across each for various reasons, and it isn’t easy to manually keep IDs in sync across them.

    Specifically, in the “taxQuery” part:
    <!-- wp:query {"queryId":14,"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false,"taxQuery":{"category":[13,12]}},"align":"wide","layout":{"inherit":true}} -->

    Is there a way to use the category slug or some other method to not have hard-coded IDs in the index.html template file?

    Thank you for your help.

    • This topic was modified 2 years ago by dkrape.
    • This topic was modified 2 years ago by dkrape.
    • This topic was modified 2 years ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • Thread Starter dkrape

    (@dkrape)

    Quick addition: I considered adding a filter to intercept the query block by query ID and in the function change the taxonomy query to use hard-coded slugs instead. This is a fairly ugly hack obviously, but it would allow me to keep everything in code and consistent across dev/staging/prod without synchronizing the databases.

    Unfortunately, it seems when using render_block, they query has already been run and the block rendered, so it is not possible to change the query. Additionally, it seems there is currently no way to add a filter for block queries. There is a PR to merge one in though: https://github.com/WordPress/wordpress-develop/pull/2185 (no indication when that would happen).

    • This reply was modified 2 years ago by dkrape.
Viewing 1 replies (of 1 total)
  • The topic ‘Hard-coded category IDs when using full-site-editor query block’ is closed to new replies.