• Hello,

    I have four custom post types and I want to show their titles listed on the front page using the query loop block (or a custom query block) on the 2022 Block theme.

    With wp_query I am able to do this in the 2021 theme but am not yet familiar with block themes and the query loop block, which seems to only allow listing of one post type.

    The other three custom post types are visible in the dropdown in the query loop block after using ‘show_in_rest’ => true, when registering the post type…just can’t select multiple post types.

    If someone can point me in the right direction, that would be great. Thanks.

    • This topic was modified 2 years, 6 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The post type field has no multi attribute, so I’m not sure how you selected multiple types with any theme. It could have possibly been removed in an update, but that seems like an odd thing to do.

    Anyway, here we are. It is possible to alter the query vars of any posts query through the “pre_get_posts” action hook. The callback would need to discern this particular query from all others. It could then set the “post_type” query var to be an array of desired post types.

    The fact the block occurs on your front page is helpful. The callback could check is_front_page() (for the main query, not the current block). Perhaps the post type requested by the block could be further confirmation that we have the right query.

Viewing 1 replies (of 1 total)
  • The topic ‘Front Page listing Titles for Four Custom Post Types Using Query Loop block’ is closed to new replies.