The correct function is get_the_ID().
https://developer.ww.wp.xz.cn/reference/functions/get_the_id/
Are you using the function in the loop?
So this is the function:
<?php $meta_key = 'post_id'; $id = get_the_id();?>
<a href="#">" data-type="text" data-inputclass="form-control" data-pk="<?php echo $id;?>" class="text-field">
<?php echo get_post_meta( $id, $meta_key, true ); $id = $meta_key = '';?>
</a>
Not being used in a loop, this is the function from the post type:
// get all bugs from custom post type
$args = array(
'post_type' => 'bugs',
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
);
What ID are you trying to retrieve? Please show the full code via pastebin or gist.
Here is the pastebin: https://pastebin.com/n0BXXHcE
I want to display the ID of the post under “ticket ID”
Is the ticket ID the ID of the CPT or a field of the CPT? Using “get_the_ID()” implies the former, but I’m not sure what you’re doing with the meta keys.
The meta keys are for the bootstrap editable field.
The ID is the ID, of the post from the CPT.
OK, it appears you’re using it in a loop, after a call to the_post(). What do you get as the value returned by get_the_ID() in line 46 before you reset it to a blank in line 48?
It apears blank, on the front-end. Doesn’t do anything.
What happens if you use $the_query->post->IDinstead of get_the_ID()?
Steve,
Thank you for all your help. I appreciate it, I figured it out, I just did this
<?php $post_id = get_the_ID(); echo $post_id; ?>
And this displayed the ID as I expected.