PHP WordPress the_content()

Where can I find the file where the_content() gets the value from post_content in the database?

I wanted to do the concept but with another content from the database,
So far, I’ve added a new column to the database ex. post_content2
How can I get its value by using something like

Read More
 <?php the_content2(); ?>

I tried looking at post-template.php and found the function but not how it gets the value from the database post_content.

Related posts

1 comment

  1. From the comments above, and a more complete answer:

    1. Do not modify core WP tables. Either use post_meta functions, or add a new table.

    2. the_content() is just a convenience function that directly accesses the posts table, content column. You can do the same thing at any time by getting the value from the database, and passing it through apply_filters('the_content', $my_custom_content);. If you want to write your own the_content2() function, it could / should be done like so (using the post_meta method mentioned above):

      function the_content2() {
          // Global in the current post so we can get the ID
          global $post;   
          // Load your custom content
          $my_content = get_post_meta($post->ID, 'my_custom_content'); 
          // Echo it out (like the_content()) applying 'the_content' filters
          echo apply_filters('the_content', $my_content);
      }
      

    If you want to figure out how to SAVE this content, then you can read this writeup:

    How to Create Custom Meta Boxes in WordPress

    edit
    It’s worth noting that this functionality is already available in a few different plugins you can install. In my experience Custom Field Suite is the most reliable and easy to use (but that’s just my opinion).

Comments are closed.