0

CReating a template to load content in an iframe on the same page - I have not even got as far as using ajax to avoid reloading the whole page as the form submit is not working. The submit button returns an empty URL with no query string:( Any thoughts

<?php
/*
    Template Name: Options Page
*/
get_header();
?>
<?php
$options= $_GET['options']? $_GET['options'] : "option1";
$options = ucfirst($options);
?>
<section class="post-meta fix post-nothumb  media"><section class="bd post-header fix" ><section class="bd post-title-section fix"><hgroup class="post-title fix">
    <h1 class="entry-title pagetitle"><?php echo $options; ?></h1>
</hgroup></section></section></section>
<form id="oselector" method="GET" action="<?php the_permalink(); ?>"> 
    <select name="options">
        <option <?php if ($_GET['options'] == 0) { ?>selected="true" <?php }; ?> value="0">Select Option</option>
        <option <?php if ($_GET['options'] == "option1") { ?>selected="true" <?php }; ?> value="option1">Option 1</option>
        <option <?php if ($_GET['options'] == "option2") { ?>selected="true" <?php }; ?> value="option2">Option 2</option>
    </select>
    <input type="submit" value="Submit">
</form>
</div></div></div></div></div></div>
<iframe id="theme" src="http://www.example.com/<?php echo $options; ?>/" seamless style="border-radius: 7px; border: 1px solid rgb(218,218,219);margin: 0 auto;width: 95%; height: 100%; overflow-x: auto; min-height:800px" >
<p>Your browser does not support iframes.</p>
</iframe>
<?php
get_footer();

1 Answer 1

1

The problem is problably here:

<form id="oselector" method="GET" action="<?php the_permalink(); ?>">

Your code is not in the WordPress Loop. According to the Function Reference (emphasis added):

the_permalink() - Displays the URL for the permalink to the post currently being processed in The Loop. This tag must be within The Loop, and is generally used to display the permalink for each post, when the posts are being displayed. Since this template tag is limited to displaying the permalink for the post that is being processed, you cannot use it to display the permalink to an arbitrary post on your weblog. Refer to get_permalink() if you want to get the permalink for a post, given its unique post id.

You might try this:

<form id="oselector" method="GET" action="<?php echo get_permalink( get_queried_object_id() ); ?>">
2
  • I am afraid that that did not solve my problem. I changed it from get permalink to xava.ie/page-slug - The code above is a template and I have applied the template to a page with the slug page-slug - that should work for me but it doesnt:( Commented May 20, 2013 at 7:33
  • It works for me in a template file. You can test this by using this near the top of the template file: wp_die( '<pre>' . var_export( get_permalink( get_queried_object_id() ), true ) . '</pre>' );. If it is not working, then some code in theme or a plugin is changing it. Commented May 20, 2013 at 10:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.