Support

Account

Home Forums ACF PRO 2nd page based off of data on first page Reply To: 2nd page based off of data on first page

  • You don’t create flyer-1. Flyer-1 will be generated from page-property.php because it’s the same page but then with a query var.

    In functions.php add this

    function add_vars( $vars ) {
        $vars[] = "subpage";
        return $vars;
    }
    add_filter( 'query_vars', 'add_vars' );

    Now you can access http://www.domain.com/landing-1/?subpage=flyer (the word flyer can be anything you want). But this doesn’t do anything yet, because you have not prepared page-property.php to do something different when this query var is used.

    In page-property.php add the following:

    if ( get_query_var( 'subpage' ) ) {
        // if ?subpage is used, load the content for flyer-1
    } else {
        // load normal landing-1
    }

    If the url has ?subpage then load the content for flyer-1.
    If the URL does not have ?subpage it loads the normal content for landing-1.

    So if you now go to http://www.domain.com/landing-1 you see the ‘normal’ content.
    If you go to http://www.domain.com/landing-1?subpage=flyer-1 you see the ‘new’ content.

    Since they’re both the same page (and same ID) you can easily retrieve values from landing-1 and show them on the generated ?subpage=something page (I hope this makes sense).

    You can then make the url pretty with some regex.
    Please note this is NOT the working regex, but it’s an idea in which direction to go. I just don’t have the time to dive into regex now 🙂

    function rewrite_urls() {
        add_rewrite_rule( 'page/([a-zA-Z0-9-]+)/?$', 'index.php?post_type=page&subpage=$matches[1]', 'top' );
    }
    add_filter( 'init', 'rewrite_urls', 1, 3 );