1

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

 <?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.

4
  • the_content() gets the value from the posts table in your database (from the column titled content). Commented Nov 30, 2015 at 15:45
  • 2
    I'm not sure what you're asking, but I'll note that it's almost always a bad idea to modify either core wordpress code, or core wordpress tables. Any modification to wordpress should be done through plugins or themes, otherwise you either can't upgrade wordpress, or upgrades will destroy your code. Commented Nov 30, 2015 at 15:45
  • 4
    Editing the wordpress table schema is a very bad idea - instead use a meta field Commented Nov 30, 2015 at 15:46
  • Probably something like en-gb.wordpress.org/plugins/advanced-custom-fields would save you a lot of effort Commented Nov 30, 2015 at 15:46

1 Answer 1

6

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, but about the modification I did, will removing the column/row i added completely restore the table to normal?
If that's the only modification that you made to the table, then it should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.