How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?

Looks like all I needed to do was put the template_include filter inside of the init action. Source: https://stackoverflow.com/a/50037707/5749974 add_action( ‘init’, function () { $product_base = ltrim( get_option( ‘woocommerce_permalinks’ )[ ‘product_base’ ], “https://wordpress.stackexchange.com/” ); add_rewrite_rule( “{$product_base}/([^/]+)/test”, ‘index.php?product=$matches[1]&test=1’, ‘top’ ); add_filter( ‘template_include’, function( $template ) { if ( get_query_var( ‘test’ ) ) { $template = get_stylesheet_directory() … Read more

Add pagination to a template loaded by query variable

After a bit of digging over the weekend, I found the solution and indeed, it is a rewrite rule with the paged variable added add_rewrite_rule(‘collection/men/page/([^/]+)/?$’,’index.php?post_type=collection&men=yes&paged=$matches[1]’,’top’); Pagination now works in the custom template loaded by query variable. i.e. localhost/sample-site/collection/men/page/2 loads the next page instead of a 404 error

Pass form input via url variable

The first form: <form method=”post” action=”some-url.php”> <input type=”email” placeholder=”Email address” value=”” name=”email”> <input type=”submit” value=”Submit” name=”email-submit”> </form> Then in some-url.php: if( isset($_POST[’email’] ) $email = $_POST[’email’] The post method would be preferred here since it won’t create server log entries that include the user’s email address. You should also do this over SSL since you … Read more