doushenxu7294 2013-12-06 13:10
浏览 36
已采纳

需要在functions.php中获取帖子ID

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!

  • 写回答

1条回答 默认 最新

  • dongyun3335 2013-12-06 14:51
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题