dos3018 2011-08-14 18:57
浏览 40
已采纳

在不同的php文件中访问WordPress功能?

How am I able to call the built-in WordPress functions (specifically wp_get_user()) in a different file (say, x.php)?

Here's my situation. If I call wp_get_current_user() on the index.php file within my theme directory, it works just perfectly.

However, if I have x.php and called that, I got an error. I googled around, and am now including wp-load.php (at it's correct path). Now it's just giving me an associated array with no values.

The associated array is:

WP_User Object ( [data] => [ID] => 0 [id] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [first_name] => [last_name] => [filter] => )

I tried including index.php in this file, and it still spits out that stuf above, instead of the correct information (which is shown by a print_r on index.php).

Thank you!

  • 写回答

2条回答 默认 最新

  • duanji5116 2011-08-14 19:15
    关注

    try also including the header <?php require('{correct_path}/wp-blog-header.php'); and if that doesn't work also try re-declaring the variables your using to global $var in your wordpress setting php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流