wordpress:当我更改永久链接时,类别ID和帖子ID无法获取

时间:2012-07-06 08:18:27

标签: php wordpress wordpress-plugin

如何在functions.php文件中获取post id和category id?

  function myFilter($query) 
    {

        if ($query->is_category)
        {
           //how to I get current caegories 
           //tried $currently_listing_categories = $query->query_vars['category__in'];  
but its not working when I turn on SEo friendly url
        }

        if ($query->is_single)
        {
           //how do I get current  id of the post
          //tried $thePostID = $query->query_vars['p'];
 but not working when I turn on SEO friendly url
        }
}

add_filter('pre_get_posts','myFilter');

即使我打开SEO友好网址(帖子名称为永久链接),我也必须获得current_listing_categories和thePostID

比你非常

0 个答案:

没有答案