Title: Custom fields in a query loop?
Last modified: July 12, 2024

---

# Custom fields in a query loop?

 *  Resolved [ohlookitsdany](https://wordpress.org/support/users/ohlookitsdany/)
 * (@ohlookitsdany)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/custom-fields-in-a-query-loop/)
 * I work for a small nonprofit, and a while back on an older version of WordPress,
   I created a custom post type that has a bunch of custom metadata fields. Now 
   we’re working on a brand refresh and I’ve upgraded us to WordPress 6.5.5 and 
   thought I’d rebuild our theme using Twenty Twenty-Four as a base, since the new
   site editor would streamline things for us. However, I’m having trouble querying
   for those custom fields in the custom post type.
 * The Query Loop block sees the custom post type, and even allows me to filter 
   by our custom taxonomies, but in the “Post Template” part of the query loop block,
   I’d like to display some of that custom metadata (certification type and location
   in this specific instance) if available. (You can see our existing card display
   and what I’m trying to replicate here: [https://living-future.org/program/lbc/](https://living-future.org/program/lbc/))
 * On previous versions of WordPress, I’ve had a “case-studies-card.php” file that
   displays that information like so:
 *     ```wp-block-code
       <?php$certification = get_post_meta($post->ID, 'cert_type_dropdown', true);$location = get_post_meta($post->ID, 'location_text', true);?>...<div class="post-card__primary">    ...    <?php else : ?>        <?php the_title( '<h2 class="post-card__title mdc-typography mdc-typography--headline6">', '</h2>' ); ?>    <?php endif; ?>    <h4 class="post-card__subtitle mdc-typography mdc-typography--subtitle2"><?php echo $certification ?></h4></div><div class="post-card__secondary mdc-typography mdc-typography--body2">    <p><?php echo $location ?></p></div>
       ```
   
 * I’m trying to basically add that as a pattern that I can drop into a Query Loop
   block, but I can’t get it to display that information.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-fields-in-a-query-loop%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [Mahangu Weerasinghe](https://wordpress.org/support/users/lastnode/)
 * (@lastnode)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/custom-fields-in-a-query-loop/#post-17889439)
 * > The Query Loop block sees the custom post type, and even allows me to filter
   > by our custom taxonomies, but in the “Post Template” part of the query loop
   > block, I’d like to display some of that custom metadata (certification type
   > and location in this specific instance) if available.
   > […]
   > I’m trying to basically add that as a pattern that I can drop into a Query 
   > Loop block, but I can’t get it to display that information.
 * This [Extending the Query Loop block](https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/extending-the-query-loop-block/)
   howto from [WordPress Developer Resources](https://developer.wordpress.org/) 
   seems to detail what you are looking to do here, using an example:
 * > Let’s go on a journey, for example, of setting up a variation for a plugin 
   > which registers a `book` [custom post type](https://developer.wordpress.org/plugins/post-types/).
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/custom-fields-in-a-query-loop/#post-17890758)
 * There is a tutorial series on the Developer Blog that does a deep dive into using
   custom fields in queries, patterns, templates, etc.:
    - [Building a book review site with Block Bindings, part 1: Custom fields and block variations](https://developer.wordpress.org/news/2024/05/06/building-a-book-review-site-with-block-bindings-part-1-custom-fields-and-block-variations/)
    - [Building a book review site with Block Bindings, part 2: Queries, patterns, and templates](https://developer.wordpress.org/news/2024/06/06/building-a-book-review-site-with-block-bindings-part-2-queries-patterns-and-templates/)
 * I wrote the series, so I’m happy to help with any specifics if you run into trouble.
 *  Thread Starter [ohlookitsdany](https://wordpress.org/support/users/ohlookitsdany/)
 * (@ohlookitsdany)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/custom-fields-in-a-query-loop/#post-17891098)
 * Thank you so much, Justin, this looks like EXACTLY what I needed. I know some
   coding basics, but I’m mostly just self-taught. Working at a nonprofit means 
   having to adapt to resource-scarce environments, hah hah, so I have to kinda 
   learn as I go. I’ll be sure to reach out if I run into any issues.

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

The topic ‘Custom fields in a query loop?’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [ohlookitsdany](https://wordpress.org/support/users/ohlookitsdany/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/custom-fields-in-a-query-loop/#post-17891098)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
