[wp-hackers] Rewrite rules after unknown url structure

William Satterwhite whsatterwhite at gmail.com
Tue Oct 22 15:54:14 UTC 2013


Are your SEM landing pages actual pages or another custom post type? If
they're another custom post type you could add an additional parameter
specifying the post type in your add_rewrite_rules function.

 $aNewRules = array('sample-page/([^/]+)/?$' =>
'index.php?*post_type=sem_pages*&pagename=sample-page&sid=$matches[1]');


On Tue, Oct 22, 2013 at 11:49 AM, Jesse Friedman <me at jes.se.com> wrote:

> Hi Everyone
>
> Thanks in advance for any help.
>
> We have a plugin that turns all of our pages and CPT's into SEM landing
> pages simply by appending ?sem=true to the end of the url.  Google has
> recently decided to start declining our campaigns because of this
> parameter.
>
> So right now I have
> domain.com/coverage/vehicle/?sem=true
>
> I need it to be
> domain.com/coverage/vehicle/sem
>
> I have the following code, which works well to a point.
>
> function add_query_vars($aVars) {
>     $aVars[] = "sid";    // represents the name of the product category as
> shown in the URL
>     return $aVars;
> }
>
> add_filter('query_vars', 'add_query_vars');
>
> function add_rewrite_rules($aRules) {
>     $aNewRules = array('sample-page/([^/]+)/?$' =>
> 'index.php?pagename=sample-page&sid=$matches[1]');
>     $aRules = $aNewRules + $aRules;
>     return $aRules;
> }
>
> add_filter('rewrite_rules_array', 'add_rewrite_rules');
>
> The problem is that, this code assumes this parameter is only going to be
> used on pages where pagename=='sample-page'
>
> I need to be able to get the var on any page, post, cpt, etc...
>
> I'm find with doing
>
> domain.com/sem/sample-page
>
>
> Can someone point me in the right direction?
>
>
> --
> thanks
>
> *jesse friedman*
> jes.se.com *
> *
> Book: Web Designers Guide to WordPress -
> http://wdgwp.com/onamazon<http://wdgwp.com/onamazon>
> Twitter: @professor <http://twitter.com/professor>
> Facebook: Like<
> https://www.facebook.com/pages/Jesse-Friedman/204793299545174>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177


More information about the wp-hackers mailing list