• Hi @takayukister,

    _post_title, _post_url, etc, are only set inside “the loop”, but sometimes, there’s a need to capture them outside “the loop”, e.g. in a popup that’s hooked to wp_footer.

    It should be possible to hook get_queried_object() at a suitable point to capture default values for the special mail tags, and use the current code to override these values if the form is embedded inside “the loop”.

    I’m not saying it’s easy (I’ve tried), but you’re better at this than I am, so I have faith.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    As you wrote, _post_* mail-tags work only inside the loop. If you insist on using them outside the loop, simply create a loop there. That’ll be much easier.

    Thread Starter Gal Baras

    (@galbaras)

    Since forms can be embedded outside the loop, the functionality of the mail tags is incomplete. Strictly speaking, “_post” implies that the user wants post attributes, but really, these are used to track which page the form was submitted on, whether it’s a post or not.

    Would it be enough to use rewind_posts()? A secondary query requires knowing the queried object, which seems to be a problem, so this seems much simpler.

    If this will work, will you please consider adding it to the plugin when there is no valid post? I can’t imagine any case where someone uses these fields, but wants them empty when the form is outside the loop.

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    used to track which page the form was submitted on

    You can use [_url].

    Thread Starter Gal Baras

    (@galbaras)

    Thank you. This gets me half of the way there.

    It looks like, at least for singular pages, it’s possible to also get the title from the URL. This code is adapted from StackExchange, and I haven’t tested it, but it could go on line 180 of includes/submission.php:

    
    $back_id = url_to_postid( $this->meta['url'] );
    if ( $back_id > 0 ) {
        $meta['title'] = get_the_title( $back_id );
    }
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set special mail tags outside the loop’ is closed to new replies.