course_id on page / in shortcode

Home Forums Legacy Support Support queries Other issues course_id on page / in shortcode

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #258954
    fdittmar
    Participant
    Team, How can I place the course_id (the post number) on a page? What's the best way for me to do this on the course-status page? I place a 3rd party shortcode onto my page. Something like: [3rdPartyPlugin dir="/abc/" intro="SomeText"] This works fine, no problems. Now I'd like to place the ID of the course that this page belongs to into that 3rd party shortcode so that I get something like this: [3rdPartyPlugin dir="/abc/'Insert CourseID call from Vibe'" intro="SomeText"] so that it becomes something like [3rdPartyPlugin dir="/abc/12345" intro="SomeText"] I understand from https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes that I can't place a [xx] shortcode inside another shortcode so we can't call [xx [yy] zz] Can you help me work out how to get the post id into my shortcode please. I know from another post here that @Logan mentioned to a customer that there are multiple ways of retrieving that id. thank you
    #259381
    Veronica
    Moderator
    hi, well we need complete information about this like
    1. which plugin you are using
    2. where you are going to put this shortcode
    3. are you trying to access it on any URL?
    4. yes right we can't place a shortcode within another shortcode
    5. and in the last can you please share the url where you find: I know from another post here that @Logan mentioned to a customer that there are multiple ways of retrieving that id
    #260055
    fdittmar
    Participant
    This reply has been marked as private.
    #260056
    fdittmar
    Participant
    I've got other topics on this but for your and other users benefit I may mention that I'm using https://www.wpcloudplugins.com/ to replace Buddydrive filesharing. Diana and Alex (with their 3 and 5 years experience here) have already tried to help on the full replacement question (which isn't possible right now) so I'm trying to use custom course nav on the course status page to place my dropbox shortcode onto the specific course page. To automate that though, I want to be able to get the course ID into the file directory structure automatically. So, I know what I am asking and why so I'm not looking for suggestions on using other ways to achieve this - that is already done. Would be great if you could find me a code solution or ask one of the seniors to help you with that if you're not yet familiar with it. These questions on getting info onto the pages do pop up regularly in these forums but there isn't a comprehensive answer anywhere yet I think. A normal add_shortcode declaration with a function to retrieve the ID wouldn't work in this case I think because of the related shortcode [brackets] so I have to rely on you coming up with something different or vibe specific. Many thanks
    #260518
    Veronica
    Moderator
    hi, sorry for the delay in response due to support holiday so basically what  you want is that to get the id of the course status page right! if it's the same then we can provide you the shortcode for this.
    #260533
    fdittmar
    Participant
    Hi, No prob - I know about sundays and how busy you are. It's also not that urgent as I can currently copy all the directory names (the course IDs) into our courses manually so nothing in the site is broken. This is just to automate the process for us going forwards. So, Yes to your question (which I don't fully understand because I thought that I had explained my need fairly well already). I need that course ID in a format so that it can be inserted into the other shortcode which is entered in all our backend course pages via new custom-course-nav sections which then output the result into the course menu. Thank you.  
    #260548
    fdittmar
    Participant
    This reply has been marked as private.
    #260852
    Veronica
    Moderator
    ok i try to write the shortcode for this.
    #262325
    fdittmar
    Participant
    btw, these are some of the posts I checked that reference the course id: https://wplms.io/support/forums/topic/get-current-course-id/ https://wplms.io/support/forums/topic/bp_course_get_unit_course_id-is-return-a-false-course-id-from-course-status/ https://wplms.io/support/forums/topic/add-course-id-and-unit-id-as-a-class-in-tag-in-unit-pages/ https://wplms.io/support/forums/topic/course-id-in-woo-commerce-checkout/ https://wplms.io/support/forums/topic/get-instructor-by-course-id/
    #262586
    Veronica
    Moderator
    well the topic links that you have provided are different from your's because your need is different from others! i will provide the shortcode to you tomorrow please ping me  
    #262868
    fdittmar
    Participant
    @veronica That's nice of you, thank you.
    #263613
    fdittmar
    Participant
    @veronica you asked for a Ping...
    #264025
    Veronica
    Moderator
    yes thanks, here is the shortcode: add_shortcode('drivecoursecustom','drivecoursecustom');
    function drivecoursecustom($atts,$content){
      $meta = get_the_ID();
      if(!empty($meta))
      {
        $result = do_shortcode('[outofthebox dir="/'.$meta.'" mode="files"]');
      }
      return $result;
    } add this shortcode:[drivecoursecustom] use above shortcode in the tab content instead of this: '[outofthebox dir="/65" mode="files"]'
    #264050
    fdittmar
    Participant
    @veronica Well, that works perfectly. (my actual shortcode is a lot longer but I adapted your method) I just want to say: You are very smart for doing it this way. It hadn't even occurred to me to try to rewrite the whole shortcode in one. I was trying with 'get_the_ID', ' $post->ID', 'get_queried_object_id()' and other ways to retrieve the post ID to then declare it in Javascript so that I could retrieve/stick it into the middle of my own shortcode. Much more complicated. Your method is simple, and because my original shortcode is the same for all courses, works perfectly in the system now. I can now replace the Course Buddydrive with a Dropbox folder automatically for every course. Much better. I appreciate you doing this. All the best  
Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘course_id on page / in shortcode’ is closed to new replies.