WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 6 months ago

Last modified 6 months ago

#48906 closed enhancement (fixed)

Twenty Twenty: Add context for twentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list

Reported by: msaari Owned by: SergeyBiryukov
Milestone: 5.3.1 Priority: normal
Severity: minor Version:
Component: Bundled Theme Keywords: has-patch commit
Focuses: Cc:

Description

The twentytwenty_get_post_meta() function is used in Twenty Twenty to output post meta on two locations: top of the post and the bottom of the post. Which location is used, depends on the $location parameter of the function.

The function also has two action hooks that can be used to output additional post meta information, for example if you have custom taxonomies, you can output those. However, the action hooks only get the $post_id as a parameter, so whatever custom post meta you want to add, you have no context information and no way to figure out whether you're adding to the post top or post bottom location: you're doing both at the same time.

There's a simple solution to this. The function uses $post_meta array to list which post meta fields are displayed and this is already filtered based on location. All that is needed is to pass the $post_meta array as a parameter for the action hooks.

Attachments (2)

template-tags.patch (462 bytes) - added by msaari 6 months ago.
Patch for /inc/template-tags.php
48906.diff (2.5 KB) - added by SergeyBiryukov 6 months ago.

Download all attachments as: .zip

Change History (8)

@msaari
6 months ago

Patch for /inc/template-tags.php

#1 @SergeyBiryukov
6 months ago

  • Component changed from Themes to Bundled Theme

#2 @SergeyBiryukov
6 months ago

  • Milestone changed from Awaiting Review to 5.3.1

#3 @SergeyBiryukov
6 months ago

  • Keywords has-patch commit added

Hi there, welcome to WordPress Trac! Thanks for the ticket and the patch.

As far as I can see, passing both $post_meta and $location would be helpful here.

48906.diff does that and adjusts the documentation accordingly.

#4 @msaari
6 months ago

Yes, adding $location would definitely make sense.

#5 @SergeyBiryukov
6 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 46832:

Twenty Twenty: Pass $post_meta and $location values to twentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list actions to provide better context.

Props msaari, SergeyBiryukov.
Fixes #48906.

#6 @SergeyBiryukov
6 months ago

In 46833:

Twenty Twenty: Pass $post_meta and $location values to twentytwenty_start_of_post_meta_list and twentytwenty_end_of_post_meta_list actions to provide better context.

Props msaari, SergeyBiryukov.
Merges [46832] to the 5.3 branch.
Fixes #48906.

Note: See TracTickets for help on using tickets.