iammikerodriguez
iammikerodriguez

Reputation: 379

Need to get the Post ID inside functions.php

I've been at this issue for HOURS now. I need some help or a push in the right direction at least, because I'm stumped.

Issue: I need to get the post ID inside functions.php

I'm using a plugin called SS Quiz. This plugin is a quiz making plugin, in which you make a quiz on the backend and display it using shortcodes inside your WP WYSIWYG editot. Simple, just like lots of plugins out there.

SS Quiz has a hook in which once the quiz is submitted, it will excute a block of code. Below is the exact code and documentation:

add_action('ssquiz_finished', 'after_quiz_done', 10, 4);

function after_quiz_done( $quiz_id, $user_id, $questions_right, $total_questions )
{
    // do stuff here
}
hook is triggered when SSQuiz is finished by the user

What i'm trying to do is get the post id of the current post/page in which the quiz is on, and execute a block of code simply returns the post id. I've tried everything from using the global $post to setting up postdata(setup_postdata()) inside the function. Nothing has worked. I can return thing like current logged in user, but simply not the post id.

Can anyone test this on their end and see how they can get the post ID? Whether it be on a live server or locally. I just need a push in the right direction at this point.

ANY help would be greatly appreciated!

Upvotes: 0

Views: 890

Answers (1)

mjhinch
mjhinch

Reputation: 791

Maybe you need to edit the plugin.

In the plugin where the action is called:

do_action( 'ssquiz_finished', $info->quiz->id, $info->user->id, $info->questions_right, $info->total_questions );

Add the post ID to the parameters. It's using a $info object which is setup in ssquiz_start() when the short_code runs, there you will be able to get the post ID using $global and add it to the $info object.

Upvotes: 1

Related Questions