• en_fer

    (@n_feragnoli)


    Hello, I’m working on a block theme for the first time.
    I’m facing this scenario:

    • I have several custom post types (they show up in REST and all…)
    • I have an archive page for tags (mysite.xx/tags/my-tag)
    • I need to have a list of all custom posts types in the tags archive page (ideally sorted by post type)

    now … do I really need to create a custom block for that..?
    I might be really bad in searching but I can find very little docs about the way the query works in block themes.
    Clearly the mysite.xx/tags/my-tag – on itself – is the main query. In a classic theme vars from the main query would be available and retrievable by any other snippet of php in template_parts and the such… but… now..?
    That’s clearly not happening when patterns are loaded and ‘composed’ in templates…
    The query loop block does allow custom queries on a per-block basis but… they are – indeed – custom queries. Totally unrelated to the main query and the context of variables available.

    Has anyone any pointers on where to start from..?
    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    In general, post queries still all utilize WP_Query::get_posts() one way or another. Thus you can still use “pre_get_posts” action hook to modify queries. The difficulty comes in recognizing the correct query to alter. AFAIK tag archive requests are still considered the main query, even with block themes. You’d still need to verify that one of the tag query vars is set and it’s not an admin query.

    For other queries such as for a query loop, often there is a unique set of query vars distinguishing the query loop from all other queries. Another possible technique is to add your callback just before it’s actually needed, then having the callback remove itself on entry to avoid use in any other queries.

    Thread Starter en_fer

    (@n_feragnoli)

    @bcworkz hi, thanks for the reply.

    You’d still need to verify that one of the tag query vars is set and it’s not an admin query.

    yes, that’s the main issue.
    honestly, starting the development of a block theme for the first time is kind of a steep slope…
    the amount of informations available in the various guides is pretty confusing and not very complete to anybody (read: me) who has little familiarity with react (or even with the command-line, actually).
    even resources such as fullsiteediting.com give a lot of details for granted.
    there’s some explanation about how things work but not about the why.

    as of now the basic concept behind the whole idea of the FSE system powering a block theme seems to come pretty short.
    I might be wrong but … wordpress is supposed to be a cms (kind of, at least).
    if that’s the case, what if not the query loop is the main tool to manage content..? I mean, the whole game here is – to begin with – make the right database calls, or am I missing something..?

    wyiwyg editing in gutenberg and the fse sure does for a -somehow – welcome functionality but its ‘architecture’ seems to be plagued with contradictions…
    you should be able to see what you get yet query vars definition and manipulation – to name one aspect – has to be buried inside your theme functions.php while the query loop block in your template page might or might not reflect the filters applied to it…

    the state-of-the-art of the FSE experience, at the moment, seems to be as such:
    even just to define a block variation one needs to manage three different idioms (php, json and jsx or whatever…) while – at the same time – use some sort of hack hidden in fucntions.php to steer the output towards the desired result.

    if anybody has resources that clearly explain how to find one’s way through all that, please share, thank you

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

The topic ‘Where’s the query..?’ is closed to new replies.