WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried using

$my_id = 7;
$post_id_7 = get_post($my_id); 
echo $post_id_7->post_content;

based on the documentation here.

The article I'm trying to retrieve has Short Code, which is picked up by a plugin on my site, and then formatted into HTML.

The problem is when I output the post_content to the site, the short code isn't picked up by the plugin, and I effectively just write out the short code straight to the browser.

Is there a way to get the short code evaluated properly? Or am I using the wrong function?

share|improve this question
up vote 10 down vote accepted

Post's object field contains raw content as it is stored in database. This should format it to how it appears when retrieved with template tags:

$content = apply_filters('the_content', $content);

This filters runs number of formatting functions, including shortcodes parsing. Something close to this:

>>>>>   the_content
8   (object) WP_Embed -> run_shortcode (1) 
    (object) WP_Embed -> autoembed (1) 
10  wptexturize (1) 
    convert_smilies (1) 
    convert_chars (1) 
    wpautop (1) 
    shortcode_unautop (1) 
    prepend_attachment (1) 
11  capital_P_dangit (1) 
    do_shortcode (1) 
share|improve this answer
Thank you SO MUCH. I have been looking on the codex for like an hour. – Joseph Oct 16 '10 at 22:23
@Joseph - Though many in the core WordPress community are very proud of the Codex I too find it extremely difficult to use to find anything in it unless you already know what you are looking for. Thank goodness for WordPress Answers! – MikeSchinkel Oct 17 '10 at 7:32
exactly what I was looking :) – Atif Mohammed Ameenuddin Jun 17 '11 at 9:42
@MikeSchinkel I tend to do a text search on a local copy of core when I'm in that situation... but the codex usually clues me into what text to do the search on ;-) – WraithKenny Mar 2 '12 at 17:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.