• I am having some trouble passing variables through permalinks to a custom post page.

    Here is the goal – I am making a Contest plugin for a client who wants to use this on multiple sites – so it must be easy to install and work on multiple sites (hoping to not change .htaccess).
    The Contest plugin works like this – the user enters an email and gets 1 entry into the contest, and then gets a special link to post on facebook and other networks. When a friend enters his email, the original person gets credit and an additional entry into the contest.

    I was able to make this all work perfectly with normal URLs and Get Data

    <a href="<?php echo get_permalink(); ?>?affiliateID=<?= $affiliateID ?>"><?php echo get_permalink(); ?>?affiliateID=<?= $affiliateID ?></a>

    The URL has ?affiliateID= in the structure. And that is fine for normal links. But Facebook tends to strip links and takes out everything after the ?

    I decided that passing the affiliateID via permalink would be the best. But I am having trouble.

    The best scenario would be making this work:
    https://website.com/contest/ipad-giveaway/12djj387dj3489dj/facebook/

    And I would get the affiliate ID and the affiliate source

    [Code moderated as per the Forum Rules. Please use the pastebin]

    There are some // out codes that were not working.

    When I tried to do the rewrite rule using index.php?p=$matches[1], it works to get to the page, but the additional parameters don’t pass.

    add_rewrite_rule('CD/[/]?([^/]*)[/]?([^/]*)[/]?([^/]*)$', 'index.php?pagename=about&cdid=$matches[1]&cai=$matches[2]&cas=$matches[3]','top');

    This works, and the variables will pass variables to the about page – but it doesn’t really do me much good there other than showing that variables pass.

    I have an idea that if I can get https://website.com/contest/ipad-giveaway/ to be described as index.php?post_type=contest&postname=ipad-giveaway and get that to display a page, I might be in business – but it doesn’t work that way.
    I’m not sure how to call a custom post type using index.php?……….
    I’ve looked online for hours, but I can’t find what I’m looking for.

    I would appreciate someone helping me through this – I am pretty sure iut can be done – but I keep on failing. >_<

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ryanITLab

    (@ryanitlab)

    OK – this plugin is really helpful for understanding the permalink structure!
    https://www.askapache.com/wordpress/rewriterule-viewer-plugin.html#aadl

    Thread Starter ryanITLab

    (@ryanitlab)

    This works. I’ll just leave this here. This has now been resolved.

    function add_my_var($public_query_vars) {
        $public_query_vars[] = 'cdid'; // contest ID
        $public_query_vars[] = 'cai'; // Affiliate
        $public_query_vars[] = 'cas'; // Affiliate Source
        return $public_query_vars;
    }
    add_filter('query_vars', 'add_my_var');
    
    function do_rewrite() {
    	 add_rewrite_rule('CD/[/]?([^/]*)[/]?([^/]*)[/]?([^/]*)$', 'index.php?contestdomination=$matches[1]&cai=$matches[2]&cas=$matches[3]','top');
    }
    add_action('init', 'do_rewrite');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Types and Permalink Variables’ is closed to new replies.