Getting Post, Page, CPT and Archive page IDs using URL

42 Views Asked by At

I am currently using url_to_postid() to get the ID from the URL which is later used to get the other language page in WPML using that ID.

$last_visited_id = url_to_postid( $last_visited_url );

This also works fine for getting Post ID, Page ID, and CPT ID. But the issue is getting the archive page URLs like Blog Page, Shop page, etc.

As url_to_postid() function returns 0 for www.domainname.com/blog/ or www.domainname.com/shop/ pages, I cannot get the respective language pages in WPML.

I tried using the below function as well. Here the issue is, that I don't have the POST TYPE value and also this doesn't work for the BLOG Archive or Shop Archive page.

get_page_by_path($page_path, $output, $post_type);
0

There are 0 best solutions below