Add A Saved Variable To The End Of Each RSS Feed Post URL

Good Day All.
Okay. Ive given it a shot for the past 3 hours and I just can't seem to find the spot, file, function, whatever it takes to add a piece of content grabbed from a URL and place it at the end of each RSS feed post.
Let me see if I can explain.

I have an affiliate site at http://shop.intimatetickles.com
The wordpress rss feed comes in at http://shop.intimatetickles.com/shop/feed

For my affilliates (about 60 at this time) they add to the end of the base url ?tickles= and their affiliate number, so the URL looks like http://shop.intimatetickles.com?tickles=17 for example.

I want my affiliates to be able to submit a feed. I also have a system that will drip post RSS feed items to social media, and I would like to give them use of this to post product pages to social media.

IF I ACHIEVE the task of add the affiliate code to the end of each product url obtained from the feed.

So I used $myaffid = htmlspecialchars($_GET["tickles"]);

which successfully grabbed the 17 (in my tests)

Now I need to figure out where, how to place the varaiable ($myaffid) so that each URL gets this added to the end of it.

I tried to write a function....
function add_aff_id($permalink)
{
return $permalink . $myaffid;
}
add_filter('the_permalink_rss','add_aff_id');

But this does not seem to work.

Any ideas?

Thanks in advance.

D. Storme

  • Sajid
    • DEV MAN’s Sidekick

    Hi Deryk,
    Hope you are doing good today :slight_smile:

    I don't think you can get the ID and append it this way. Because the filter hook for permalink only triggered at the time of generating the RSS feed.

    So appending the ID at the end of home URL would not work and we need to append the ID at the end of feed URL. This way we can get the ID of affiliate and append it at the end of rss link.

    Finally your RSS feed would look like this:
    http://shop.intimatetickles.com/shop/feed?tickles=17

    And the code would be like this:

    function add_aff_id($permalink)
    {
    	if( isset($_GET['tickles']) ){
    		$myaffid = htmlspecialchars($_GET["tickles"]);
    
    		$permalink = add_query_arg( 'tickles', $myaffid, $permalink );
    
    	}
    
    	return $permalink;
    }
    add_filter('the_permalink_rss','add_aff_id');

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Kind Regards,
    Sajid

  • Deryk
    • The Incredible Code Injector

    Thanks Sajid, that seems to have worked. My feed title now includes whatever id is placed in
    ?tickles=

    Now......

    At the end of each feed there appears the line
    "The post [post title which is a hyperlink] appeared first on [Site name which is a hyperlink]

    I need the two areas in bracks above to ALSO contain the ?tickles=(id) at the end of it
    Or
    get rid of this line altogether.

    Can't seem to find where this line is firing from.

    Thanks for your suggestions to this problem.

  • Deryk
    • The Incredible Code Injector

    LOL. nevermind. This final line is a feature of Yoast SEO. Duh. I got this. You guys are the bomb. Somehow, everytime I ask a question, I get an awesome answer, and just by asking the question my brain jumps to the right solution.

  • Sajid
    • DEV MAN’s Sidekick

    Hi Deryk,
    Hope you are doing good today :slight_smile:

    I am glad to know your issue is resolved and thanks for kinds words, it means a lot. If you have any question in future, please don't hesitate to ask, more than happy to help :slight_smile:

    Kind Regards,
    Sajid

  • Sajid
    • DEV MAN’s Sidekick

    Hi Deryk,
    Hope you are doing good today :slight_smile:

    I tested it again on my own site running WP 4.6 and its working just fine for me (see the screenshot).

    Also, I used one function and one filter of WordPress core that does not indicate any notice about these being remove/deprecated.
    https://developer.wordpress.org/reference/functions/add_query_arg/
    https://developer.wordpress.org/reference/hooks/the_permalink_rss/

    There must be some thing else on your website that is interfering with it. I would recommend you run a plugin/theme conflict test as described in our getting support manual to find out the culprit.

    Take care and have a nice day :slight_smile:

    Best Regards,
    Sajid

  • Deryk
    • The Incredible Code Injector

    Thanks Sajid,
    I made a slight modification and everything came back up to working fine.

    function add_aff_id($permalink)
    {
    $myaffid = '?tickles=' . htmlspecialchars($_GET["tickles"]);
    return $permalink . $myaffid;
    }
    add_filter('the_permalink_rss','add_aff_id');

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.