0

Is there a way to filter get_page_by_path()? I am trying to allow duplicate slugs for pages, so that two pages can have the same slug if they have different meta value for a specific meta key. Thanks for the help in advance!

1 Answer 1

1

Theres no filter for that function. You can find the code in wp_includes/post.php (Obviously don't edit it there). Core File

5
  • Do you think there might me a workaround for what I am trying to achieve? Oct 21, 2019 at 19:31
  • That’s a hard one. The only way I can think of is to copy and rename that function in your theme, add the conditional in that function then alter the theme or whatever to use the new function. It’s an interesting case to use the same slug. Why not use one page with a query vars that decides which version to show?
    – KGreene
    Oct 22, 2019 at 2:56
  • I think that only works with posts, not with pages (query vars). My idea is to have two same slugs for pages if they have a different meta. I tried pre_get_posts, but I reverse engineered that the core ends using get_page_by_path() in parse_request Oct 22, 2019 at 3:45
  • What’s the problem you’re trying to solve by having two pages with the same slug? Maybe if we zoom out we can find a solution that works.
    – KGreene
    Oct 22, 2019 at 7:50
  • Well there are pages which have the meta "language". Two pages can have the same slug when the meta "language" is not the same. I do not want to use taxonomies, as the choice for the meta is "hardcoded", but am open to another suggestions. Oct 22, 2019 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.