Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:48:12+00:00 2026-06-09T10:48:12+00:00

A newbie at wordpress, trying to figure how to retrieve a specific post content

  • 0

A newbie at wordpress, trying to figure how to retrieve a specific post content into a div.

This is what I have as of now,

<div style="margin-top: 100px;">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
    <?php endif; ?>
</div>

while this works great, I have some questions,

1 – Is this fine? I spoke to some people who “know” WP, and they said I should avoid getting posts into my html.

2 – If I replace the above code with,

<div style="margin-top: 100px;">
    <?php $postId = 1; get_post($postId) ?>
    <?php the_content(); ?>
</div>

It doesn’t work.

3 – What modifications do I need to make to this code to make it work?

REQUEST: please don’t move this to wordpress.stackexchange.com, as there is minimal activity there.

cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:48:13+00:00Added an answer on June 9, 2026 at 10:48 am

    Take a look at the Function Reference for get_post
    http://codex.wordpress.org/Function_Reference/get_post

    The examples are illustrative. To get the content of the post, you would do something like this:

    <?php
      $my_id = 7;
      $post_id_7 = get_post($my_id); 
      $content = $post_id_7->post_content;
    ?> 
    

    Note that we have used get_post to retrieve the database record we are interested in, and from among the fields returned, we are making use of post_content.

    This is different from using the_content, which displays the content of the post currently being processed by The Loop.
    http://codex.wordpress.org/Function_Reference/the_content

    I imagine the former approach is better for what you are trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie in php and Wordpress. I'm trying to create a script that
newbie here, so thanks in advance for help! I have a Wordpress site with
I'm a wordpress newbie trying to add dynamic posts and pages through get requests.
I'm creating a Wordpress plugin and, being a newbie in the development on this
I'm a newbie in WordPress. I'm trying to read information from a custom table
I'm a veteran Django programmer and a newbie in WordPress. In Django, we have
Newbie to C++ but I am a Java programmer. Trying to learn C++ now.
Newbie :( Tweaking my way through tutorials but 36 hours can't figure this one
I'm a newbie in Django and in WordPress if you create a Post called
I am developing site with WordPress and I'm newbie for WordPress. WP adds <p>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.