Search code examples
phpwordpressshortcode

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.


Solution

  • your can try this,

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