Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_the_ID() returning 1 for every post in Query Loop block #49840

Closed
PH4NTOMiki opened this issue Apr 14, 2023 · 1 comment
Closed

get_the_ID() returning 1 for every post in Query Loop block #49840

PH4NTOMiki opened this issue Apr 14, 2023 · 1 comment
Labels
[Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed

Comments

@PH4NTOMiki
Copy link

Description

I created custom post type with custom field youtube_url and in Query Loop block it's impossible for me to access /show that value to the user, so I tried making custom shortcode and putting the Shortcode block inside Query Loop/Post Template with value [inject_yt_url] and then creating that shortcode with following code using Code Snippets plugin

add_shortcode( 'inject_yt_url', 'yt_shortcode' );
function yt_shortcode( $atts ) {
	return get_post_meta(get_the_ID(), 'youtube_url', true);
}

but it didn't work so I tried just showing ID using this code:

add_shortcode( 'inject_yt_url', 'yt_shortcode' );
function yt_shortcode( $atts ) {
	return get_the_ID();
}

and it always shows 1

and I also tried this with the same result:

add_shortcode( 'inject_yt_url', 'yt_shortcode' );
function yt_shortcode( $atts ) {
	global $post;
	return $post->ID;
}

Step-by-step reproduction instructions

above

Screenshots, screen recording, code snippet

No response

Environment info

WP 6.2
Nginx

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@Thelmachido Thelmachido added [Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. labels Apr 14, 2023
@carlomanf
Copy link

Duplicate of #43053

@talldan talldan added the [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed label Apr 17, 2023
@talldan talldan closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed
Projects
None yet
Development

No branches or pull requests

4 participants