如何在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
比你非常