WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Cant get php to work inside shortcode content

[Resolved] Cant get php to work inside shortcode content

  • I tried several solutions from looking at similar questions within the site but it won’t work me. =( Please help.

    This is an excerpt from my original code:

    <form action="" method="get">
    <input type="text" name="search" value="">
    <input type="submit" value="Search">
    <?php echo do_shortcode('[expand]
    <input type="checkbox" name="title" <?php if(isset($_GET['title'])) echo "checked='checked'"; ?>>
        <label for="ti">Title</label></td>
    [/expand]'); ?>
    </form>

    Basically, I want my checkboxes to remain checked, if they were checked before hitting submit. Unfortunately, it’s been hours and I can’t get the php to work inside the shortcode.

    Please help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi

    @esmi

    Forum Moderator

    Where is this code being added?
    Where is the shortcode being defined?

    Hello! Please see my code excerpt from the first post. I don’t know but you may have missed it when I was editing it before you replied?

    esmi

    @esmi

    Forum Moderator

    I did look at your code. I have no idea from that where it is being used. And the shortcode is not defined in the snippet you posted above.

    I am writing the code from a pod page:
    http://wordpress.org/plugins/pods/
    Is that what you mean?

    <?php if(isset($_GET['title'])) echo "checked='checked'"; ?> works if I remove the <?php echo do_shortcode('[expand] and [/expand]'); ?>

    So I guess it doesn’t work inside do_shortcode? How do I get it to work?

    esmi

    @esmi

    Forum Moderator

    I don’t think that’s necessary since my question doesn’t have anything to do with pods but simply with making the PHP work inside a shortcode.

    EDIT:

    <form action="" method="GET">
        <input type="text" name="search" value="">
        <input type="submit" value="Search">
        <?php
         $check=isset($_GET['title']) ? "checked='checked'" : '';
         echo do_shortcode('[expand]
         <input type="checkbox" name="title" '.$check.' ><label for="ti">Title</label></td>
         <input type="submit" value="Search">
         [/expand]');
        ?>
    </form>

    The above code is the solution. Thanks to Spencer for replying!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Cant get php to work inside shortcode content’ is closed to new replies.
Skip to toolbar