Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This particular website is using Tubepress to display a youtube video gallery. Now, Tubepress recommends that, to define which video goes to the front part of the gallery, we should append the id to the url, like this:

http://mysite.com/videos.php?tubepress_video=somevideoid

So, i already have a an option stored with the default video ID for the videos page, but i'm getting some trouble in dinamically appending that value to the URL everytime the video page is loaded.

So far, i've tried URL Rewrites, with no luck, and then i found this: Custom URl parameter and it seemed to be exactly what i want. I figured there's also a page_link filter hook, but there's no documentation on it. So this still isn't working and i'm not quite sure why.

Me actual code looks like this:

function append_parameter( $link, $my_parameter ) {

    if(is_page('videos')) {
        $my_parameter = get_option('featured_video_id');

        if ( isset($my_parameter) ) { 
            $link = add_query_arg( 'tubepress_video', $my_parameter );
        }
        return $link;
        }
    }
add_filter( 'page_link','append_parameter', 10, 2 );

any ideas?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

In the example you link this is how the parameter is added:

add_query_arg( 'sort', $my_parameter, $link );

However, in your example you missed the link parameter.

Does it work if you replace it with:

$link = add_query_arg( 'tubepress_video', $my_parameter, $link );

?

share|improve this answer
    
Not really. The last parameter is optional and defaults to $_SERVER[]; –  moraleida Mar 30 '12 at 12:46
    
@moraleida True, but that is not really what you want. I tried it and it works for me with added $link parameter. Is your video page actually a Wordpress page? If it is not, this will not work. The documentation for page_link and other link-filter can be found here –  tim Mar 30 '12 at 13:03
    
The video page is a wp page, up and running. And i got $link back and now i get the correct query. But i guess this hook isn't what i thought, then. I wanted a hook that would redirect any links to mysite.com/videos/ to mysite.com/videos/?tubepress_video=somevideoid, so appending values before page load... –  moraleida Mar 30 '12 at 13:18
1  
I am not quite sure what you mean by "appending values before page load", but I think that the parameter is not displayed in the links to the page itself, but added right before/at the time the link is called? I do not think that wordpress supports that, but you could either just set the get parameter yourself by adding $_GET["tubepress_video"] = get_option('featured_video_id'); at the beginning of video.php or - if somevideoid is fixed - use the servers rewrite engine. Both are not great ways, but I do not think that there really are better alternatives. –  tim Mar 30 '12 at 13:45
    
$_GET["tubepress_video"] = get_option('featured_video_id'); worked perfectly. Sometimes i just hate the fact that i know more about wordpress than about PHP itself. Thanks! –  moraleida Mar 30 '12 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.