You should be able to get the current url from $url = add_query_arg()
.
Then assuming, the structure: www.example.com/page/subpage/news/ID/post
you can use preg_match
to extract /page/subpage/news
. Then it would be simple matter of using get_page_by_path();
.
If that fails you can then check /page/subpage/
and finally /page
.
Related Posts:
- Removing hierarchical pages in the permalink
- How to Remove Slug From Database?
- Get the url of a page template without using the page slug and ID
- Remove -2 from URL; no duplicate pages, no images, no pages in trash
- Host frontpage via example.com and everything else via example.com/blog
- Edit permalink for certain pages
- cannot link a external url, present page url acting as parent url
- “-2” Being added to end of URL (no duplicate pages, no pages in trash)
- How do I structure my permalinks in WordPress?
- Nested permalink without dummy parent page
- Is it possible to get a page link from its slug?
- How does WordPress create URLs that Apache knows about?
- Stop WordPress appending `-2` to the end of my url after i change it
- Get current URL (permalink) without /page/{pagenum}/
- How to get pretty URLs with add_query_arg in permalinks
- Creating custom permalink structure for languages
- Adding another word in front of post url
- Page begins with number, WordPress adds 2
- why does anchor name add a slash to url?
- Subdomains to pages
- Passing variables through permalink structure
- How to create a permalink structure for posts in a specific category
- How to make draft posts or posts in review accessible via full url / slug?
- Remove subfolders from URL
- flexible rewrite ‘ramble’ URLs with WordPress
- How to increase the character limit for post name of 200?
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- Relative or Absolute Paths for Flash Video Player Files
- Should I use relative or absolute urls when pointing to internal pages
- WordPress 3.4 Permalinks Redirection Problem
- How to Modify Existing Rewrite Rules?
- Can two products with the same name but different category produce unique URLs?
- Page Attachment Permalink Structure based on Menu Order?
- How to reset canonical URLs / fix redirect loop
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- Permalinks by page/post name returning 404
- wordpress api using rest_route for other pages
- How to get post object on blog template
- Force wordpress to display page with same url structure as categories
- Is it possible for a custom post type and sub pages of a page with the same slug as the custom post type to share a slug?
- How can i have a custom post type with more slugs for each post?
- URL rewriting: removing the site’s basename for a specific category
- get_permalink returning site home url instead of the url of slug being passed
- display dynamic content based on url slug on custom page
- How to generate a list of all urls
- Let me choose permalinks
- How to use all tags in post permalinks
- Path to Pages Resolves to Archive instead of Actual Content
- Changing permalink name redirects to another template?
- Permalink opens attachment instead of page
- How do I reclaim either deleted pages or their permalinks?
- Permalink of a page that has already been deleted
- Unique one time use URL
- Remove parent page from url
- Test site pages go to main site
- Getting back a permalink from custom url
- how to get a list of all top level pages
- Bulk append URL (add word to slug)
- How are WordPress Page URLs affected by permalink settings?
- Get a link to paged() part?
- replacing post ID by custom post name in url
- Access posts while mod_rewrite is broken
- Page content doesn’t display when published but does when previewed as draft?
- Update page breaks permalinks
- Post with no tag permalink problem
- replicate url permalink after migrating to wordpress
- How to remove slug from front page?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- Link to a page before launch
- WordPress keeps removing query var from the URL
- Change Project permalink to custom URL
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- My WP homepage works, but the other pages don’t when accessing from out side of my network
- Using a template file for a specific custom URL
- Extra url paths as variable
- Passing parameter through permalink structure
- Can I link to content dynamically from a page to a new page?
- Woocommerce product page 404 not found
- rebuilding/ rewriting a url to make it SEO friendly
- Page returns 404 for specific permalink
- Get value from URL with different types of parameters
- a way to support totally different url structure
- Change all pages permalinks instead of hierarchical to have id of the page
- Remove/hide a specify category-name from the url
- How to change URL of my pages?
- Page permalink ending in “-2”
- Imported posts using wrong domain name
- Change the permalinks structure
- When using number in url it is redircting to same page but when using character it redirects to 404
- Using a taxonomy value as part of a post URL
- Custom Permalink Base
- Category pagination first link works, remaining don’t
- Permalinks of New Pages and their Parents
- Change permalink in wp-property
- Why doesn’t my page know it’s a page (won’t return true for is_page())?
- Include language variable in url
- How to get the perfect WordPress, WooCommerce, Custom Post Type pretty permalinks?
- WordPress keep redirecting me to random URLs
- Standard Htaccess directives disappear by themselves
- Change default URL (or permalinks) in the back-end