LearnPress / learnpress

LearnPress WordPress LMS Plugin by ThimPress
https://thimpress.com/learnpress
237 stars 139 forks source link

How To get Page url in learnPress ? #527

Open bhaveshdarji386 opened 1 year ago

bhaveshdarji386 commented 1 year ago

Hello, I am trying to get current page url. but I am not able to get I tried many ways to get id or url but not succeed global $post; echo $post->ID;

global $wp_query; echo $wp_query->post->ID;

global $wp; echo home_url( $wp->request )

not able to get id

global $wp; echo home_url( $wp->request );

global $wp; echo add_query_arg( $wp->query_vars, home_url() );

global $wp; echo add_query_arg( $wp->query_vars, home_url( $wp->request ) );

www.host.com/wp-json/lp/v1/lazy-load/course-curriculum

I am getting this url but not getting browser one it should be something like

http:/host.com/courses/cambridge-igcse-physics-paper-2-mcqs-extended/quizzes/4-physics-2021-may-june-23

Please help me to find this solution I am new in wordpress. Your response will be highly appreciate. Thank You in advance ^_^

rajaeinet commented 1 year ago

Hi If you want to get a page permalink in wordpress, you can use the get_permalink() (+) function and pass page ID to it:

<?php
global $post;
echo get_permalink( $post->ID );

But in learnpress, if you be on a lesson page, the $post->ID returns the course page ID instead of the lesson page ID! In this case, you can call learn_press_get_current_url() function from learnpress plugin. Like below:

echo learn_press_get_current_url();

Good luck :)

rajaeinet commented 1 year ago

Also you can see the function source code here: https://github.com/LearnPress/learnpress/blob/215b3283c3bf304f1214e2e585416455e89e5d8b/inc/lp-core-functions.php#L276-L310