Obtain content from the publication before the representation

I am currently working on a short code function, where I need to access the content of a publication, before its representation.

If I do it like that

$ content = get_the_content (get_the_ID ());

It gives me the content already rendered. How can I access the content before rendering?

What I'm trying to do is create a shortcode, which generates a table of contents of specific headlines that are placed with shortcodes. For that reason, the content still needs to have the short codes undelivered in it.

As requested, here is the complete code, so I might have an idea of ​​what I'm trying to do.


function nimaji_shortcodes () {

add_shortcode (& # 39; nimaji_toc & # 39 ;, & # 39; generate_toc & # 39;);

}

add_action (& # 39; wp_head & # 39 ;, & # 39; nimaji_shortcodes & # 39;);

function genera_toc () {

$ content = get_the_content (get_the_ID ());
krumo ($ content);

// Look for a specific shortcode, containing information about the holders.
$ pattern = & # 39; / [x_custom_headline level="(.*?)"(.*?)](. *?) [/x_custom_headline]/ & # 39 ;;

preg_match_all ($ pattern, $ content, $ matches);

$ levels = $ matches[1];
$ titles = $ matches[3];

$ toc_meta = genera_toc_meta ($ levels, $ titles);

$ html = & # 39;
    & # 39 ;; foreach ($ toc_meta as $ key_2 => $ level2) { foreach ($ level2 as $ key_3 => $ level3) { if ($ key_3 == 0) { $ html = "
  1. $ level3
  2. "; } else if ($ key_3 == 1) { $ html = "
      "; $ html = "
    1. $ level3
    2. "; } else if ($ key_3 == sizeof ($ level2) - 1) { $ html = "
    3. $ level3
    4. "; $ html = "
    "; } else { $ html = "
  3. $ level3
  4. "; } } } $ html = & # 39;
& # 39 ;; returns $ html; } generate_toc_meta function (array $ levels, array $ title) { $ new_levels = array (); $ i = - 1; $ j = 0; foreach ($ levels as $ key => $ level) { if ($ level == & # 39; h2 & # 39;) { $ i ++; $ j = 0; $ new_levels[ $i ][ $j ] = $ title[$key]; } else if ($ level == & # 39; h3 & # 39;) { $ j ++; $ new_levels[ $i ][ $j ] = $ title[$key]; } else { continue; } } returns $ new_levels; }