I’m not very sure of what you’re trying to achieve, but I hope this answer can help. 🙂
-
With the way your custom post type is being registered, WordPress will create custom rewrite rules such as below for the CPT’s single post pages:
RegEx: ballinfo/([^/]+)(?:/([0-9]+))?/?$ Query: index.php?balls=$matches[1]&page=$matches[2] -
So for the following question:
how do I know if a site was called with
/ballinfoor notWhen the single page of a
ballspost is visited, the URL would have/ballinfo/as inexample.com/ballinfo/an-example-balls-post.Now to programmatically check if the URL contains
/ballinfo/, you can check if the$requestproperty of the globalWPclass instance starts with aballinfo/like so:global $wp; if ( preg_match( '#^ballinfo/#', $wp->request ) ) { echo 'Site was called with the /ballinfo<br>'; } echo '$wp->request is ' . $wp->request . '<br>'; -
And for the following question:
How do I know if my rewrite rule was matched and used?
You can match the rule (RegEx) with the one in the
$matched_ruleproperty of the globalWPclass instance.For example, for the single
ballspost pages, where the rule uses the RegEx pattern as in point #1 in this answer, try this:global $wp; if ( 'ballinfo/([^/]+)(?:/([0-9]+))?/?$' === $wp->matched_rule ) { echo 'Yay, my rewrite rule was matched!<br>'; } else { echo 'Not matched. $wp->matched_rule is ' . $wp->matched_rule . '<br>'; }
And you may already know this, but if you just wanted to check if the requested URL is for a CPT post/archive/etc., you can use is_singular(), is_post_type_archive(), and other appropriate WordPress conditional functions/tags.