we have a situation where, for the same permalink, there could be both a page and a custom post, for example "car".
https://www.example.com/aaa/bbb/carPostID
Normally at that address there is a custom post "car".
So we use add_rewrite_rule
to make a specific custom post load
Example:
add_rewrite_rule(
'^aaa/bbb/(.*)$',
'index.php?car=$matches[3]',
'top'
);
Currently if a page is created with that form of url we get 404.
We would like instead, if there is a page and there is not our custom post, that the page "wins" and is rendered.
Is it possible, for example, to concatenate two equal rules and if there is no post for the first one the second one is used?
add_rewrite_rule(
'^aaa/bbb/(.*)$',
'index.php?car=$matches[3]',
'top'
);
add_rewrite_rule(
'^aaa/bbb/(.*)$',
'index.php?page=$matches[3]',
'top'
);
Is it possible? Thank you
index.php?car=XYZ
when processing it, so what you asked needs to make sense and still work if they visit that ugly URL because they are the same URL as far as WP is concerned