• The templating engine of WP seems to be mighty inconsistent.

    1. the_title() has a parameter that allows me to use it as a variable in my PHP: the_title('', '', FALSE).
    2. the_ID() is equally useful if not more (for doing some custom SQL in the page) but doesn’t have this feature to send parameters and get the ID as a value instead of displaying it.
    3. the_content() also doesn’t have any parameter for returning the html-stripped (text only) to use in PHP instead of simply displaying it.

    Any ideas on how I can get the value of the current post’s ID and content? I want to use this in my Single Post template to run a query (to show related posts).

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • 2. get_the_ID()

    3. get_the_content()

    Not an oft mentioned feature and its more a recent development, but most (though not all) template tags have a corresponding get_the_* function that returns its value. There is even a – surprise! – get_the_title().

    In fact, many of the the_* functions are mere (echo) wrappers for get_the_* functions.

    Thread Starter erick_paper

    (@erick_paper)

    Wow, this is splendid, thank you!!!

    Thanks, this was exactly what I’ve been looking for.

    I wonder why such an important function is so unknown. I need get_the_ID() more often then I need the_ID()!!!!

    It should be at least mentioned on codex!!!! It’s practically impossible to find it!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘the_ID for use in the page, not display?’ is closed to new replies.