Opened 22 months ago
Last modified 13 months ago
#58223 new defect (bug)
Twenty Twenty: twentytwenty_get_post_meta needs global $has_meta
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Bundled Theme | Keywords: | needs-patch |
Focuses: | template | Cc: |
Description (last modified by )
There’s a bug in the Twenty Twenty theme in twentytwenty_get_post_meta
. The bug prevents the action hooks twentytwenty_start_of_post_meta_list
and twentytwenty_end_of_post_meta_list
from displaying additional meta data when the default meta data fields are not populated.
The variable $has_meta
must be true for any meta to be displayed. It is set to false
initially and is only set to true
if one of the default meta are provided. For single-bottom
, if no tags are in the post, $has_meta
will be false regardless of additional meta attempting to be displayed by the action hooks.
I solved the bug by defining $has_meta
as a global inside twentytwenty_get_post_meta
. From there, I was able to modify its value to true within my action hook function.
Hope this can be fixed in the published version of the theme so I don’t have to use a hacked version.
I posted on the theme support page and was asked to post a bug in this forum instead. Link to my theme support post: https://wordpress.org/support/topic/twentytwenty_end_of_post_meta_list-needs-global-has_meta/
Change History (3)
#2
@
20 months ago
- Keywords needs-patch added
- Summary changed from twentytwenty_end_of_post_meta_list needs global $has_meta to Twenty Twenty: twentytwenty_get_post_meta needs global $has_meta
#3
@
20 months ago
I believe I just declared $has_meta as a global here:
<?php // If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output. if ( $post_meta && ! in_array( 'empty', $post_meta, true ) ) { // Make sure we don't output an empty container. global $has_meta; $has_meta = false;
Then in my function that runs on the twentytwenty_end_of_post_meta_list
action, I set it to True like this:
<?php $GLOBALS['has_meta'] = true;
Hi and thanks for the report!
Could you share how you added the global in your site?