0

I have a custom template file containing some HTML tags and get_post_meta function. I want to insert the HTML data into post_content column. Is there a wordpress function or SQL function to save into post_content column? I couldn't find a good anwswer on the internet.
This is my custom template file.

<?php
    // the post name is cryto name.
    $cryto_name = get_the_title();

    // Cryto Variables from SQL table
    $ccf_company = get_post_meta( get_the_ID(), 'ccf_company', true );
    $ccf_jurisdiction = get_post_meta( get_the_ID(), 'ccf_jurisdiction', true );
    $ccf_symbol = get_post_meta( get_the_ID(), 'ccf_symbol', true );
    $ccf_maximum_supply = get_post_meta( get_the_ID(), 'ccf_maximum_supply', true );

?>

<h2>Features of <?php echo $cryto_name ?></h2>

<figure class="ht-post__content table">
    <table>
        <thead>
            <tr>
                <th>Features</th>
                <th class="has-text-align-center" data-align="center"><?php echo $cryto_name ?> (<?php echo $ccf_symbol ?>)</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Developer</td>
                <td class="has-text-align-center" data-align="center"><?php echo $ccf_company ?></td>
            </tr>
            <tr>
                <td>Country</td>
                <td class="has-text-align-center" data-align="center"><?php echo $ccf_jurisdiction ?></td>
            </tr>
            <tr>
                <td>Symbol</td>
                <td class="has-text-align-center" data-align="center"><?php echo $ccf_symbol ?></td>
            </tr>
            <tr>
                <td>Max Supply</td>
                <td class="has-text-align-center" data-align="center"><?php echo check_max_supply($db_coin_max_supply, $ccf_symbol) ?></td>
            </tr>
    </table>
</figure>

I already made a sql table and this template is working. However, I'm trying to save this HTML output into post_content column.

6
  • I tried to make a custom Gutenberg block with this php template file, but I don't know much about React so I gave up..uhhhh... Commented Jun 20, 2022 at 14:59
  • 1
    can you explain a little better what you're doing? examples? Code?
    – rudtek
    Commented Jun 20, 2022 at 15:00
  • @rudtek Thanks for the interest. I have edited above. Commented Jun 20, 2022 at 15:06
  • 1
    you mentioned saving the post_content column but then you've also mentioned at the very end a custom SQL table, are you talking about updating the content of a post? Or updating a column in your custom table? If you're talking about updating a posts content then SQL is not the correct way to do it. Also, the code you're trying to modify to save the HTML as well as where the HTML is coming from is missing from your question. If it's the output of your template then saving that means it would be out of date when your meta values change, it would be much easier/faster to build a block in PHP
    – Tom J Nowell
    Commented Jun 20, 2022 at 15:21
  • Otherwise I suspect that what you're asking is not your actual question/problem, but an attempt to solve it that you haven't figured out. It would be much easier to answer the question if it was "how do I embed this PHP code into a post", someone could show you how to write a server rendered block, you don't need react knowledge or a toolchain to do that
    – Tom J Nowell
    Commented Jun 20, 2022 at 16:12

0

Your Answer

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

Browse other questions tagged or ask your own question.