In a plugin, via the add_action() routine, I try to run a check. But getting the post ID as below doesn’t work, but why? What’s the correct way of getting the post ID and a related cat id?
add_action( 'wp', 'check_url', 10, 1 );
function check_url($wp){
if( is_single() ){
$cat_id = wp_get_post_categories( $post->ID );
}
}
Add
globalto your function first before using$postto make it visible inside your function (this is why we love PHP):