wordpress plugin: query post-ID in plugin?

后端 未结 3 1389
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 02:03

hey guys, maybe some of you have experience with programming wordpress plugins. I have a probably rather simpel question, but i couldn\'t find anything on the web.



        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 02:07

    Filters should return, not echo.

    function test($content) {
        global $post;
        return 'id: ' . $post->ID . '
    ' . $content; }

    In order to look at the post object properties you must bring $post into the scope of the function, that's what this line does..

    global $post;
    

    Which then allows the reference to the object's ID, eg.

    $post->ID;
    

    See here for help understanding actions and filters.
    http://codex.wordpress.org/Plugin_API

    Example filter.
    http://codex.wordpress.org/Plugin_API#Example

提交回复
热议问题