0

I am new to WordPress I made a function as a subscription form. when I want to check it on another function I use

 global $post;
    if (has_shortcode($post->post_content, 'up-vip')) {....}

I don't know why post_content retun zero : ["post_content"]=> string(0) I need it to return ["post_content"]=> string(8) "[up-vip]"

if you need more detail please let me know "

<?php

function upgrade()
{
    ob_start();
    ?>
    <form id="form" method="post">
        <div class="order-table">
            <ul class="pay">
                <li><label for="plan"><i class="fa fa-user"></i>Plans</label></li>
                <li>
                    <select class="ddl" id="plan" name="plan">
                        <option value="1month">choose a plan</option>
                    </select>
                </li>
                <li><label for="gate"><i class="fa fa-credit-card"></i>Select the Bank</label></li>
                <li>
                    <select class="ddl" id="gate" name="gate">
                        <option value="elbank">EL Bank</option>
                    </select>
                </li>
                <li>
                    <button class="button-buy"><i class="fa fa-shopping-cart"></i>BUY</button>
                </li>
            </ul>
        </div>
    </form>
    <?php
    return ob_get_clean();
}

add_shortcode('up-vip', 'upgrade');
?>
3
  • where is $post coming from? Can you tell us where the code snippet with has_shortcode is located and when it runs? It would be helpful to see the previous 20 lines of code for context
    – Tom J Nowell
    Commented Dec 4, 2023 at 9:01
  • @TomJNowell thanks for your reply. It comes from global $post; It's a form for buying a subscription. after a user clicks on the buy button. in our plugin we check it with has_shortcode could you please click on the buy button? you can see var dump log tmcd.ir//HbPV
    – D.JCode
    Commented Dec 4, 2023 at 9:39
  • are you sure that $post has the actual value? If there is no current post set then $post may not have a value yet, or have the value you thought it would. Ignore has_shortcode and check that $post is the post you expected it to be with a valid ID and the title you're expecting. Also where global $post is located is important. Be sure to include the previous 20 lines of code unmodified, hiding details even to try and be helpful hurts your question and conceals the problem
    – Tom J Nowell
    Commented Dec 4, 2023 at 12:00

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.